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>
This commit is contained in:
Mike Reed 2018-11-28 10:28:07 -05:00 committed by Skia Commit-Bot
parent 6616efbdeb
commit 32c6066ea8
10 changed files with 53 additions and 41 deletions

View File

@ -45,8 +45,8 @@ private:
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]));

View File

@ -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 @@ protected:
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 @@ protected:
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);

View File

@ -32,8 +32,8 @@ public:
}
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 ...

View File

@ -368,7 +368,8 @@ void SkGlyphRunBuilder::simplifyDrawText(
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());
}

View File

@ -180,7 +180,8 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
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 @@ void SkGlyphRunListPainter::drawForBitmapDevice(
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 @@ void GrTextBlob::generateFromGlyphRunList(GrGlyphCache* glyphCache,
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]

View File

@ -73,7 +73,8 @@ void SkOverdrawCanvas::drawPosTextCommon(const void* text, size_t byteLength, co
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);

View File

@ -85,9 +85,10 @@ void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar tex
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 @@ SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bound
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 @@ size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth,
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 @@ SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
}
// 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;

View File

@ -160,6 +160,7 @@ auto SkStrikeCache::findOrCreateStrike(const SkDescriptor& desc,
}
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(
const SkFont& font,
const SkPaint& paint,
const SkSurfaceProps& surfaceProps,
SkScalerContextFlags scalerContextFlags,
@ -167,18 +168,20 @@ SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(
{
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 @@ auto SkStrikeCache::findOrCreateStrike(
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());
}

View File

@ -115,25 +115,27 @@ public:
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,

View File

@ -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 @@ SkExclusiveStrikePtr SkPDFFont::MakeVectorCache(SkTypeface* face, int* size) {
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 {