Remove user specified typeface id.
Now that there may be multiple font managers in a process the typeface
ids must be unique across all typefaces, not just unique within a font
manager. If two typefaces have the same id there will be issues in the
glyph cache. All existing font managers were already doing this by
calling SkFontCache::NewFontID, so centralize this in SkTypeface.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2147733002
Review-Url: https://codereview.chromium.org/2147733002
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index 7304cfb..e3a311d 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -341,7 +341,7 @@
/** uniqueID must be unique and non-zero
*/
- SkTypeface(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch = false);
+ SkTypeface(const SkFontStyle& style, bool isFixedPitch = false);
virtual ~SkTypeface();
/** Sets the fixedPitch bit. If used, must be called in the constructor. */
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index 90a1eaa..4b0dd08 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -14,9 +14,10 @@
#include "SkOnce.h"
#include "SkStream.h"
#include "SkTypeface.h"
+#include "SkTypefaceCache.h"
-SkTypeface::SkTypeface(const SkFontStyle& style, SkFontID fontID, bool isFixedPitch)
- : fUniqueID(fontID), fStyle(style), fIsFixedPitch(isFixedPitch) { }
+SkTypeface::SkTypeface(const SkFontStyle& style, bool isFixedPitch)
+ : fUniqueID(SkTypefaceCache::NewFontID()), fStyle(style), fIsFixedPitch(isFixedPitch) { }
SkTypeface::~SkTypeface() { }
@@ -40,7 +41,7 @@
public:
static SkEmptyTypeface* Create() { return new SkEmptyTypeface; }
protected:
- SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { }
+ SkEmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkGScalerContext.cpp
index 1d34536..5a439b7 100644
--- a/src/fonts/SkGScalerContext.cpp
+++ b/src/fonts/SkGScalerContext.cpp
@@ -152,7 +152,7 @@
#include "SkTypefaceCache.h"
SkGTypeface::SkGTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint)
- : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
+ : SkTypeface(proxy->fontStyle(), false)
, fProxy(std::move(proxy))
, fPaint(paint)
{}
diff --git a/src/fonts/SkRandomScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp
index 6d3718c..c9cb87c 100644
--- a/src/fonts/SkRandomScalerContext.cpp
+++ b/src/fonts/SkRandomScalerContext.cpp
@@ -191,7 +191,7 @@
#include "SkTypefaceCache.h"
SkRandomTypeface::SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint, bool fakeIt)
- : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false)
+ : SkTypeface(proxy->fontStyle(), false)
, fProxy(std::move(proxy))
, fPaint(paint)
, fFakeIt(fakeIt) {}
diff --git a/src/fonts/SkTestScalerContext.cpp b/src/fonts/SkTestScalerContext.cpp
index ebe2ee1..bab6b89 100644
--- a/src/fonts/SkTestScalerContext.cpp
+++ b/src/fonts/SkTestScalerContext.cpp
@@ -115,7 +115,7 @@
}
SkTestTypeface::SkTestTypeface(SkTestFont* testFont, const SkFontStyle& style)
- : SkTypeface(style, SkTypefaceCache::NewFontID(), false)
+ : SkTypeface(style, false)
, fTestFont(testFont) {
}
diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h
index eb5db94..590c6fa 100644
--- a/src/ports/SkFontConfigTypeface.h
+++ b/src/ports/SkFontConfigTypeface.h
@@ -50,14 +50,14 @@
const SkFontConfigInterface::FontIdentity& fi,
const SkString& familyName,
const SkFontStyle& style)
- : INHERITED(style, SkTypefaceCache::NewFontID(), false)
+ : INHERITED(style, false)
, fFCI(SkRef(fci))
, fIdentity(fi)
, fFamilyName(familyName)
, fLocalStream(nullptr) {}
SkTypeface_FCI(const SkFontStyle& style, bool fixedWidth, SkStreamAsset* localStream, int index)
- : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth)
+ : INHERITED(style, fixedWidth)
, fLocalStream(localStream)
{
fIdentity.fTTCIndex = index;
diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h
index 6d050cd..3801453 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -71,8 +71,8 @@
};
protected:
- SkTypeface_FreeType(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch)
- : INHERITED(style, uniqueID, isFixedPitch)
+ SkTypeface_FreeType(const SkFontStyle& style, bool isFixedPitch)
+ : INHERITED(style, isFixedPitch)
{}
virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index c129a6b..55eec33 100644
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -436,7 +436,7 @@
SkTypeface_Mac(CTFontRef fontRef, CFTypeRef resourceRef,
const SkFontStyle& fs, bool isFixedPitch,
bool isLocalStream)
- : SkTypeface(fs, SkTypefaceCache::NewFontID(), isFixedPitch)
+ : SkTypeface(fs, isFixedPitch)
, fFontRef(fontRef) // caller has already called CFRetain for us
, fOriginatingCFTypeRef(resourceRef) // caller has already called CFRetain for us
, fHasColorGlyphs(SkToBool(CTFontGetSymbolicTraits(fFontRef) & SkCTFontColorGlyphsTrait))
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 25038dc..34d0506 100644
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -206,7 +206,7 @@
class LogFontTypeface : public SkTypeface {
public:
LogFontTypeface(const SkFontStyle& style, const LOGFONT& lf, bool serializeAsStream)
- : SkTypeface(style, SkTypefaceCache::NewFontID(), false)
+ : SkTypeface(style, false)
, fLogFont(lf)
, fSerializeAsStream(serializeAsStream)
{
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 2e619af..a8d5b12 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -35,7 +35,7 @@
SkTypeface_Android(const SkFontStyle& style,
bool isFixedPitch,
const SkString& familyName)
- : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
+ : INHERITED(style, isFixedPitch)
, fFamilyName(familyName)
{ }
diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index 0fc5180..a05cc9b 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -30,7 +30,7 @@
public:
SkTypeface_Custom(const SkFontStyle& style, bool isFixedPitch,
bool sysFont, const SkString familyName, int index)
- : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
+ : INHERITED(style, isFixedPitch)
, fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index)
{ }
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 610a300..0876fb6 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -405,7 +405,7 @@
public:
/** @param data takes ownership of the font data.*/
SkTypeface_stream(SkFontData* data, const SkFontStyle& style, bool fixedWidth)
- : INHERITED(style, SkTypefaceCache::NewFontID(), fixedWidth)
+ : INHERITED(style, fixedWidth)
, fData(data)
{ };
@@ -493,7 +493,6 @@
/** @param pattern takes ownership of the reference. */
SkTypeface_fontconfig(FcPattern* pattern)
: INHERITED(skfontstyle_from_fcpattern(pattern),
- SkTypefaceCache::NewFontID(),
FC_PROPORTIONAL != get_int(pattern, FC_SPACING, FC_PROPORTIONAL))
, fPattern(pattern)
{ };
diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h
index 11b3fb5..1119841 100644
--- a/src/ports/SkTypeface_win_dw.h
+++ b/src/ports/SkTypeface_win_dw.h
@@ -39,14 +39,14 @@
class DWriteFontTypeface : public SkTypeface {
private:
- DWriteFontTypeface(const SkFontStyle& style, SkFontID fontID,
+ DWriteFontTypeface(const SkFontStyle& style,
IDWriteFactory* factory,
IDWriteFontFace* fontFace,
IDWriteFont* font,
IDWriteFontFamily* fontFamily,
IDWriteFontFileLoader* fontFileLoader = nullptr,
IDWriteFontCollectionLoader* fontCollectionLoader = nullptr)
- : SkTypeface(style, fontID, false)
+ : SkTypeface(style, false)
, fFactory(SkRefComPtr(factory))
, fDWriteFontCollectionLoader(SkSafeRefComPtr(fontCollectionLoader))
, fDWriteFontFileLoader(SkSafeRefComPtr(fontFileLoader))
@@ -80,8 +80,7 @@
IDWriteFontFamily* fontFamily,
IDWriteFontFileLoader* fontFileLoader = nullptr,
IDWriteFontCollectionLoader* fontCollectionLoader = nullptr) {
- SkFontID fontID = SkTypefaceCache::NewFontID();
- return new DWriteFontTypeface(get_style(font), fontID, factory, fontFace, font, fontFamily,
+ return new DWriteFontTypeface(get_style(font), factory, fontFace, font, fontFamily,
fontFileLoader, fontCollectionLoader);
}
diff --git a/tests/FontMgrTest.cpp b/tests/FontMgrTest.cpp
index dd280cd..da72542 100644
--- a/tests/FontMgrTest.cpp
+++ b/tests/FontMgrTest.cpp
@@ -115,12 +115,11 @@
}
static void test_matchStyleCSS3(skiatest::Reporter* reporter) {
- static const SkFontID invalidFontID = std::numeric_limits<SkFontID>::max();
static const SkFontStyle invalidFontStyle(101, SkFontStyle::kNormal_Width, SkFontStyle::kUpright_Slant);
class TestTypeface : public SkTypeface {
public:
- TestTypeface(const SkFontStyle& fontStyle, SkFontID id) : SkTypeface(fontStyle, id, false){}
+ TestTypeface(const SkFontStyle& fontStyle) : SkTypeface(fontStyle, false){}
protected:
SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
@@ -168,9 +167,9 @@
}
SkTypeface* createTypeface(int index) override {
if (index < 0 || this->count() <= index) {
- return new TestTypeface(invalidFontStyle, invalidFontID);
+ return new TestTypeface(invalidFontStyle);
}
- return new TestTypeface(fStyles[index], index);
+ return new TestTypeface(fStyles[index]);
}
SkTypeface* matchStyle(const SkFontStyle& pattern) override {
return this->matchStyleCSS3(pattern);
diff --git a/tests/TypefaceTest.cpp b/tests/TypefaceTest.cpp
index 13196bc..4c65fa3 100644
--- a/tests/TypefaceTest.cpp
+++ b/tests/TypefaceTest.cpp
@@ -31,9 +31,9 @@
class SkEmptyTypeface : public SkTypeface {
public:
- static sk_sp<SkTypeface> Create(SkFontID id) { return sk_sp<SkTypeface>(new SkEmptyTypeface(id)); }
+ static sk_sp<SkTypeface> Create() { return sk_sp<SkTypeface>(new SkEmptyTypeface()); }
protected:
- SkEmptyTypeface(SkFontID id) : SkTypeface(SkFontStyle(), id, true) { }
+ SkEmptyTypeface() : SkTypeface(SkFontStyle(), true) { }
SkStreamAsset* onOpenStream(int* ttcIndex) const override { return nullptr; }
SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&,
@@ -76,12 +76,12 @@
}
DEF_TEST(TypefaceCache, reporter) {
- sk_sp<SkTypeface> t1(SkEmptyTypeface::Create(1));
+ sk_sp<SkTypeface> t1(SkEmptyTypeface::Create());
{
SkTypefaceCache cache;
REPORTER_ASSERT(reporter, count(reporter, cache) == 0);
{
- sk_sp<SkTypeface> t0(SkEmptyTypeface::Create(0));
+ sk_sp<SkTypeface> t0(SkEmptyTypeface::Create());
cache.add(t0.get());
REPORTER_ASSERT(reporter, count(reporter, cache) == 1);
cache.add(t1.get());