aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-03-05 14:23:47 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-07 16:24:20 +0000
commit61d56b92a4076f8afd644d015913641d691e39c8 (patch)
tree2d01f6a6eac0a678f99863ba3354e5bbf14ce584 /src/core
parent78cb579f33943421afc8423a39867fcfd69fed44 (diff)
Remove attach and detach glyph cache.
BUG=skia:7515 Change-Id: Ib978e3cf4cfffdefe6453feb520e5e73684abf2e Reviewed-on: https://skia-review.googlesource.com/112560 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkGlyphCache.cpp36
-rw-r--r--src/core/SkGlyphCache.h33
-rw-r--r--src/core/SkPaint.cpp27
-rw-r--r--src/core/SkTextToPathIter.h19
4 files changed, 47 insertions, 68 deletions
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 9bb43604a6..668f0e49b2 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -505,6 +505,23 @@ SkExclusiveStrikePtr SkGlyphCache::FindOrCreateStrikeExclusive(
return FindOrCreateStrikeExclusive(desc, creator);
}
+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);
+}
+
void SkGlyphCache::AttachCache(SkGlyphCache* cache) {
SkGlyphCache_Globals::AttachCache(cache);
}
@@ -786,22 +803,3 @@ void SkGraphics::PurgeFontCache() {
size_t SkGraphics::GetTLSFontCacheLimit() { return 0; }
void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { }
-SkGlyphCache* SkGlyphCache::DetachCache(
- SkTypeface* typeface, const SkScalerContextEffects& effects, const SkDescriptor* desc)
-{
- auto cache = FindOrCreateStrikeExclusive(*desc, effects, *typeface);
- return cache.release();
-}
-
-SkGlyphCache* SkGlyphCache::DetachCacheUsingPaint(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);
-
- return SkGlyphCache::DetachCache(SkPaintPriv::GetTypefaceOrDefault(paint), effects, desc);
-}
diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h
index 8c335af859..a161f6f448 100644
--- a/src/core/SkGlyphCache.h
+++ b/src/core/SkGlyphCache.h
@@ -148,6 +148,12 @@ public:
const SkScalerContextEffects& effects,
const SkTypeface& typeface);
+ static SkExclusiveStrikePtr FindOrCreateStrikeExclusive(
+ const SkPaint& paint,
+ const SkSurfaceProps* surfaceProps,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix* deviceMatrix);
+
template <typename ScalerContextCreator>
static SkExclusiveStrikePtr CreateStrikeExclusive(
const SkDescriptor& desc, ScalerContextCreator creator)
@@ -167,22 +173,6 @@ public:
return SkExclusiveStrikePtr(new SkGlyphCache(desc, std::move(context)));
}
- /** Detach a strike from the global cache matching the specified descriptor. Once detached,
- it can be queried/modified by the current thread, and when finished, be reattached to the
- global cache with AttachCache(). While detached, if another request is made with the same
- descriptor, a different strike will be generated. This is fine. It does mean we can have
- more than 1 strike for the same descriptor, but that will eventually get purged, and the
- win is that different thread will never block each other while a strike is being used.
- DEPRECATED
- */
- static SkGlyphCache* DetachCache(
- SkTypeface* typeface, const SkScalerContextEffects& effects, const SkDescriptor* desc);
-
- static SkGlyphCache* DetachCacheUsingPaint(const SkPaint& paint,
- const SkSurfaceProps* surfaceProps,
- SkScalerContextFlags scalerContextFlags,
- const SkMatrix* deviceMatrix);
-
static void Dump();
/** Dump memory usage statistics of all the attaches caches in the process using the
@@ -296,20 +286,17 @@ private:
class SkAutoGlyphCache : public SkExclusiveStrikePtr {
public:
- /** deprecated: use get() */
- SkGlyphCache* getCache() const { return this->get(); }
SkAutoGlyphCache() = default;
SkAutoGlyphCache(SkGlyphCache* cache) : INHERITED(cache) {}
SkAutoGlyphCache(SkTypeface* typeface, const SkScalerContextEffects& effects,
const SkDescriptor* desc)
- : INHERITED(SkGlyphCache::DetachCache(typeface, effects, desc))
- {}
+ : INHERITED(SkGlyphCache::FindOrCreateStrikeExclusive(*desc, effects, *typeface)) {}
/** deprecated: always enables fake gamma */
SkAutoGlyphCache(const SkPaint& paint,
const SkSurfaceProps* surfaceProps,
const SkMatrix* matrix)
: INHERITED(
- SkGlyphCache::DetachCacheUsingPaint(
+ SkGlyphCache::FindOrCreateStrikeExclusive(
paint, surfaceProps,
SkScalerContextFlags::kFakeGammaAndBoostContrast, matrix))
{}
@@ -318,8 +305,8 @@ public:
SkScalerContextFlags scalerContextFlags,
const SkMatrix* matrix)
: INHERITED(
- SkGlyphCache::DetachCacheUsingPaint(paint, surfaceProps, scalerContextFlags, matrix))
- {}
+ SkGlyphCache::FindOrCreateStrikeExclusive(
+ paint, surfaceProps, scalerContextFlags, matrix)) {}
private:
using INHERITED = SkExclusiveStrikePtr;
};
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index e3680713b5..210b8e5a3a 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -431,7 +431,7 @@ int SkPaint::textToGlyphs(const void* textData, size_t byteLength, uint16_t glyp
}
SkAutoGlyphCache autoCache(*this, nullptr, nullptr);
- SkGlyphCache* cache = autoCache.getCache();
+ SkGlyphCache* cache = autoCache.get();
const char* text = (const char*)textData;
const char* stop = text + byteLength;
@@ -489,7 +489,7 @@ bool SkPaint::containsText(const void* textData, size_t byteLength) const {
}
SkAutoGlyphCache autoCache(*this, nullptr, nullptr);
- SkGlyphCache* cache = autoCache.getCache();
+ SkGlyphCache* cache = autoCache.get();
switch (this->getTextEncoding()) {
case SkPaint::kUTF8_TextEncoding: {
@@ -539,7 +539,7 @@ void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar tex
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
SkAutoGlyphCache autoCache(*this, &props, nullptr);
- SkGlyphCache* cache = autoCache.getCache();
+ SkGlyphCache* cache = autoCache.get();
for (int index = 0; index < count; index++) {
textData[index] = cache->glyphToUnichar(glyphs[index]);
@@ -805,7 +805,7 @@ SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bound
SkScalar scale = canon.getScale();
SkAutoGlyphCache autoCache(paint, nullptr, nullptr);
- SkGlyphCache* cache = autoCache.getCache();
+ SkGlyphCache* cache = autoCache.get();
SkScalar width = 0;
@@ -859,7 +859,7 @@ size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth,
}
SkAutoGlyphCache autoCache(paint, nullptr, nullptr);
- SkGlyphCache* cache = autoCache.getCache();
+ SkGlyphCache* cache = autoCache.get();
GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(),
paint.isDevKernText(),
@@ -965,7 +965,7 @@ int SkPaint::getTextWidths(const void* textData, size_t byteLength,
SkScalar scale = canon.getScale();
SkAutoGlyphCache autoCache(paint, nullptr, nullptr);
- SkGlyphCache* cache = autoCache.getCache();
+ SkGlyphCache* cache = autoCache.get();
GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(),
paint.isDevKernText(),
nullptr != bounds);
@@ -1748,9 +1748,8 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
}
// SRGBTODO: Is this correct?
- fCache = SkGlyphCache::DetachCacheUsingPaint(fPaint, nullptr,
- SkScalerContextFlags::kFakeGammaAndBoostContrast,
- nullptr);
+ fCache = SkGlyphCache::FindOrCreateStrikeExclusive(
+ fPaint, nullptr, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr);
SkPaint::Style style = SkPaint::kFill_Style;
sk_sp<SkPathEffect> pe;
@@ -1768,7 +1767,7 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
SkScalar xOffset = 0;
if (paint.getTextAlign() != SkPaint::kLeft_Align) { // need to measure first
int count;
- SkScalar width = fPaint.measure_text(fCache, text, length, &count, nullptr) * fScale;
+ SkScalar width = fPaint.measure_text(fCache.get(), text, length, &count, nullptr) * fScale;
if (paint.getTextAlign() == SkPaint::kCenter_Align) {
width = SkScalarHalf(width);
}
@@ -1783,13 +1782,9 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
fXYIndex = paint.isVerticalText() ? 1 : 0;
}
-SkTextBaseIter::~SkTextBaseIter() {
- SkGlyphCache::AttachCache(fCache);
-}
-
bool SkTextToPathIter::next(const SkPath** path, SkScalar* xpos) {
if (fText < fStop) {
- const SkGlyph& glyph = fGlyphCacheProc(fCache, &fText);
+ const SkGlyph& glyph = fGlyphCacheProc(fCache.get(), &fText);
fXPos += (fPrevAdvance + fAutoKern.adjust(glyph)) * fScale;
fPrevAdvance = advance(glyph, fXYIndex); // + fPaint.getTextTracking();
@@ -1812,7 +1807,7 @@ bool SkTextToPathIter::next(const SkPath** path, SkScalar* xpos) {
}
bool SkTextInterceptsIter::next(SkScalar* array, int* count) {
- const SkGlyph& glyph = fGlyphCacheProc(fCache, &fText);
+ const SkGlyph& glyph = fGlyphCacheProc(fCache.get(), &fText);
fXPos += (fPrevAdvance + fAutoKern.adjust(glyph)) * fScale;
fPrevAdvance = advance(glyph, fXYIndex); // + fPaint.getTextTracking();
if (fCache->findPath(glyph)) {
diff --git a/src/core/SkTextToPathIter.h b/src/core/SkTextToPathIter.h
index 6de12a84ce..8bcbc21b4d 100644
--- a/src/core/SkTextToPathIter.h
+++ b/src/core/SkTextToPathIter.h
@@ -9,22 +9,21 @@
#define SkTextToPathIter_DEFINED
#include "SkAutoKern.h"
+#include "SkGlyphCache.h"
#include "SkPaint.h"
-class SkGlyphCache;
class SkTextBaseIter {
protected:
SkTextBaseIter(const char text[], size_t length, const SkPaint& paint,
bool applyStrokeAndPathEffects);
- ~SkTextBaseIter();
-
- SkGlyphCache* fCache;
- SkPaint fPaint;
- SkScalar fScale;
- SkScalar fPrevAdvance;
- const char* fText;
- const char* fStop;
+
+ SkExclusiveStrikePtr fCache;
+ SkPaint fPaint;
+ SkScalar fScale;
+ SkScalar fPrevAdvance;
+ const char* fText;
+ const char* fStop;
SkPaint::GlyphCacheProc fGlyphCacheProc;
SkScalar fXPos; // accumulated xpos, returned in next
@@ -74,7 +73,7 @@ public:
if (TextType::kPosText == fTextType
&& fPaint.getTextAlign() != SkPaint::kLeft_Align) { // need to measure first
const char* text = fText;
- const SkGlyph& glyph = fGlyphCacheProc(fCache, &text);
+ const SkGlyph& glyph = fGlyphCacheProc(fCache.get(), &text);
SkScalar width = (&glyph.fAdvanceX)[0] * fScale;
if (fPaint.getTextAlign() == SkPaint::kCenter_Align) {
width = SkScalarHalf(width);