Force clients to specify font when requesting strikecache
Bug: skia:
Change-Id: If56222039239df085d6c40e835060e91fe70940b
Reviewed-on: https://skia-review.googlesource.com/c/173166
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/bench/PathTextBench.cpp b/bench/PathTextBench.cpp
index 9bc69e7..565b3ff 100644
--- a/bench/PathTextBench.cpp
+++ b/bench/PathTextBench.cpp
@@ -45,8 +45,8 @@
SkIPoint onGetSize() override { return SkIPoint::Make(kScreenWidth, kScreenHeight); }
void onDelayedSetup() override {
- SkPaint defaultPaint;
- auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(defaultPaint);
+ SkFont defaultFont;
+ auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(defaultFont);
for (int i = 0; i < kNumGlyphs; ++i) {
SkPackedGlyphID id(cache->unicharToGlyph(kGlyphs[i]));
sk_ignore_unused_variable(cache->getScalerContext()->getPath(id, &fGlyphs[i]));
diff --git a/bench/SkGlyphCacheBench.cpp b/bench/SkGlyphCacheBench.cpp
index be99c9c..bb1f493 100644
--- a/bench/SkGlyphCacheBench.cpp
+++ b/bench/SkGlyphCacheBench.cpp
@@ -17,11 +17,12 @@
#include "sk_tool_utils.h"
-static void do_font_stuff(SkPaint* paint) {
+static void do_font_stuff(SkFont* font) {
+ SkPaint defaultPaint;
for (SkScalar i = 8; i < 64; i++) {
- paint->setTextSize(i);
+ font->setSize(i);
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
- *paint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
+ *font, defaultPaint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
SkScalerContextFlags::kNone, SkMatrix::I());
uint16_t glyphs['z'];
for (int c = ' '; c < 'z'; c++) {
@@ -54,13 +55,13 @@
void onDraw(int loops, SkCanvas*) override {
size_t oldCacheLimitSize = SkGraphics::GetFontCacheLimit();
SkGraphics::SetFontCacheLimit(fCacheSize);
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setSubpixelText(true);
- paint.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()));
+ SkFont font;
+ font.setEdging(SkFont::Edging::kAntiAlias);
+ font.setSubpixel(true);
+ font.setTypeface(sk_tool_utils::create_portable_typeface("serif", SkFontStyle::Italic()));
for (int work = 0; work < loops; work++) {
- do_font_stuff(&paint);
+ do_font_stuff(&font);
}
SkGraphics::SetFontCacheLimit(oldCacheLimitSize);
}
@@ -94,11 +95,11 @@
for (int work = 0; work < loops; work++) {
SkTaskGroup().batch(16, [&](int threadIndex) {
- SkPaint paint;
- paint.setAntiAlias(true);
- paint.setSubpixelText(true);
- paint.setTypeface(typefaces[threadIndex % 2]);
- do_font_stuff(&paint);
+ SkFont font;
+ font.setEdging(SkFont::Edging::kAntiAlias);
+ font.setSubpixel(true);
+ font.setTypeface(typefaces[threadIndex % 2]);
+ do_font_stuff(&font);
});
}
SkGraphics::SetFontCacheLimit(oldCacheLimitSize);
diff --git a/samplecode/SamplePathText.cpp b/samplecode/SamplePathText.cpp
index b56131d..72fa77b 100644
--- a/samplecode/SamplePathText.cpp
+++ b/samplecode/SamplePathText.cpp
@@ -32,8 +32,8 @@
}
void onOnceBeforeDraw() final {
- SkPaint defaultPaint;
- auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(defaultPaint);
+ SkFont defaultFont;
+ auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(defaultFont);
SkPath glyphPaths[52];
for (int i = 0; i < 52; ++i) {
// I and l are rects on OS X ...
diff --git a/src/core/SkGlyphRun.cpp b/src/core/SkGlyphRun.cpp
index 7043de8..5415719 100644
--- a/src/core/SkGlyphRun.cpp
+++ b/src/core/SkGlyphRun.cpp
@@ -368,7 +368,8 @@
if (!glyphIDs.empty()) {
fScratchAdvances.resize(runSize);
{
- auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(runPaint);
+ const SkFont font = SkFont::LEGACY_ExtractFromPaint(runPaint);
+ auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font, runPaint);
cache->getAdvances(glyphIDs, fScratchAdvances.data());
}
diff --git a/src/core/SkGlyphRunPainter.cpp b/src/core/SkGlyphRunPainter.cpp
index 60c1c91..19c3c83 100644
--- a/src/core/SkGlyphRunPainter.cpp
+++ b/src/core/SkGlyphRunPainter.cpp
@@ -180,7 +180,8 @@
SkScalar textScale = pathPaint.setupForAsPaths();
auto pathCache = SkStrikeCache::FindOrCreateStrikeExclusive(
- pathPaint, props, fScalerContextFlags, SkMatrix::I());
+ SkFont::LEGACY_ExtractFromPaint(pathPaint), pathPaint, props,
+ fScalerContextFlags, SkMatrix::I());
SkTDArray<PathAndPos> pathsAndPositions;
pathsAndPositions.setReserve(runSize);
@@ -204,7 +205,8 @@
paint);
} else {
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
- paint, props, fScalerContextFlags, deviceMatrix);
+ SkFont::LEGACY_ExtractFromPaint(paint), paint, props,
+ fScalerContextFlags, deviceMatrix);
// Add rounding and origin.
SkMatrix matrix = deviceMatrix;
@@ -740,7 +742,8 @@
SkScalar textScale = pathPaint.setupForAsPaths();
auto pathCache = SkStrikeCache::FindOrCreateStrikeExclusive(
- pathPaint, props, scalerContextFlags, SkMatrix::I());
+ SkFont::LEGACY_ExtractFromPaint(pathPaint), pathPaint, props,
+ scalerContextFlags, SkMatrix::I());
// Given a glyph that is not ARGB, draw it.
auto perPath = [textScale, run, &pathCache]
diff --git a/src/core/SkOverdrawCanvas.cpp b/src/core/SkOverdrawCanvas.cpp
index 29339e2..9c1f38f 100644
--- a/src/core/SkOverdrawCanvas.cpp
+++ b/src/core/SkOverdrawCanvas.cpp
@@ -73,7 +73,8 @@
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
this->getProps(&props);
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
- paint, props, SkScalerContextFlags::kNone, this->getTotalMatrix());
+ SkFont::LEGACY_ExtractFromPaint(paint), paint, props,
+ SkScalerContextFlags::kNone, this->getTotalMatrix());
SkFindAndPlaceGlyph::ProcessPosText(paint.getTextEncoding(), (const char*) text, byteLength,
SkPoint::Make(0, 0), SkMatrix(), (const SkScalar*) pos, 2,
cache.get(), processBounds);
diff --git a/src/core/SkPaint_text.cpp b/src/core/SkPaint_text.cpp
index 3a8dd8d..91e92f7 100644
--- a/src/core/SkPaint_text.cpp
+++ b/src/core/SkPaint_text.cpp
@@ -85,9 +85,10 @@
SkASSERT(glyphs != nullptr);
SkASSERT(textData != nullptr);
+ SkFont font = SkFont::LEGACY_ExtractFromPaint(*this);
SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
auto cache = SkStrikeCache::FindOrCreateStrikeExclusive(
- *this, props, SkScalerContextFlags::kFakeGammaAndBoostContrast, SkMatrix::I());
+ font, *this, props, SkScalerContextFlags::kFakeGammaAndBoostContrast, SkMatrix::I());
for (int index = 0; index < count; index++) {
textData[index] = cache->glyphToUnichar(glyphs[index]);
@@ -319,7 +320,8 @@
const SkPaint& paint = canon.getPaint();
SkScalar scale = canon.getScale();
- auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(paint);
+ const SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
+ auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font, paint);
SkScalar width = 0;
@@ -372,7 +374,8 @@
maxWidth /= scale;
}
- auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(paint);
+ const SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
+ auto cache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font, paint);
SkFontPriv::GlyphCacheProc glyphCacheProc = SkFontPriv::GetGlyphCacheProc(
static_cast<SkTextEncoding>(paint.getTextEncoding()), false);
@@ -618,7 +621,8 @@
}
// SRGBTODO: Is this correct?
- fCache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(fPaint);
+ const SkFont font = SkFont::LEGACY_ExtractFromPaint(fPaint);
+ fCache = SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(font, fPaint);
SkPaint::Style style = SkPaint::kFill_Style;
sk_sp<SkPathEffect> pe;
diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp
index 3e71a1a..943ddb0 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -160,6 +160,7 @@
}
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(
+ const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
@@ -167,18 +168,20 @@
{
return SkExclusiveStrikePtr(
GlobalStrikeCache()->findOrCreateStrike(
- paint, surfaceProps, scalerContextFlags,deviceMatrix));
+ font, paint, surfaceProps, scalerContextFlags,deviceMatrix));
}
SkGlyphCacheInterface* SkStrikeCache::findOrCreateGlyphCache(
+ const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix& deviceMatrix) {
- return findOrCreateStrike(paint, surfaceProps, scalerContextFlags, deviceMatrix);
+ return findOrCreateStrike(font, paint, surfaceProps, scalerContextFlags, deviceMatrix);
}
auto SkStrikeCache::findOrCreateStrike(
+ const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
@@ -188,17 +191,13 @@
SkScalerContextEffects effects;
auto desc = SkScalerContext::CreateDescriptorAndEffectsUsingPaint(
- paint, surfaceProps, scalerContextFlags, deviceMatrix, &ad, &effects);
+ font, paint, surfaceProps, scalerContextFlags, deviceMatrix, &ad, &effects);
- auto tf = SkPaintPriv::GetTypefaceOrDefault(paint);
+ auto tf = SkFontPriv::GetTypefaceOrDefault(font);
return this->findOrCreateStrike(*desc, effects, *tf);
}
-SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkPaint& paint) {
- return FindOrCreateStrikeWithNoDeviceExclusive(SkFont::LEGACY_ExtractFromPaint(paint), paint);
-}
-
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font) {
return FindOrCreateStrikeWithNoDeviceExclusive(font, SkPaint());
}
diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h
index d6b2d89..183ed6a 100644
--- a/src/core/SkStrikeCache.h
+++ b/src/core/SkStrikeCache.h
@@ -115,25 +115,27 @@
bool desperationSearchForPath(const SkDescriptor& desc, SkGlyphID glyphID, SkPath* path);
static ExclusiveStrikePtr FindOrCreateStrikeExclusive(
+ const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix& deviceMatrix);
SkGlyphCacheInterface* findOrCreateGlyphCache(
+ const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix& deviceMatrix);
Node* findOrCreateStrike(
+ const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
const SkMatrix& deviceMatrix);
- static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkPaint& paint);
-
+ // cons up a default paint, which is only needed for patheffects/maskfilter
static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkFont&);
static ExclusiveStrikePtr FindOrCreateStrikeWithNoDeviceExclusive(const SkFont& font,
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 67ee9a9..d3f3457 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -8,6 +8,7 @@
#include "SkPDFFont.h"
#include "SkData.h"
+#include "SkFont.h"
#include "SkGlyphCache.h"
#include "SkImagePriv.h"
#include "SkMacros.h"
@@ -31,9 +32,9 @@
#include "SkUTF.h"
SkExclusiveStrikePtr SkPDFFont::MakeVectorCache(SkTypeface* face, int* size) {
- SkPaint tmpPaint;
- tmpPaint.setHinting(kNo_SkFontHinting);
- tmpPaint.setTypeface(sk_ref_sp(face));
+ SkFont font;
+ font.setHinting(kNo_SkFontHinting);
+ font.setTypeface(sk_ref_sp(face));
int unitsPerEm = face->getUnitsPerEm();
if (unitsPerEm <= 0) {
unitsPerEm = 1024;
@@ -41,10 +42,10 @@
if (size) {
*size = unitsPerEm;
}
- tmpPaint.setTextSize((SkScalar)unitsPerEm);
+ font.setSize((SkScalar)unitsPerEm);
const SkSurfaceProps props(0, kUnknown_SkPixelGeometry);
return SkStrikeCache::FindOrCreateStrikeExclusive(
- tmpPaint, props, SkScalerContextFlags::kFakeGammaAndBoostContrast, SkMatrix::I());
+ font, SkPaint(), props, SkScalerContextFlags::kFakeGammaAndBoostContrast, SkMatrix::I());
}
namespace {