Bug 1485712 - set SkTypeface atomically in ScaledFonts. r=rhunt

This commit is contained in:
Lee Salzman 2018-08-23 14:58:21 -04:00
Родитель a5cee657d8
Коммит 5285c599ca
12 изменённых файлов: 62 добавлений и 63 удалений

Просмотреть файл

@ -54,7 +54,7 @@ ScaledFont::GetDefaultAAMode()
ScaledFontBase::~ScaledFontBase()
{
#ifdef USE_SKIA
SkSafeUnref(mTypeface);
SkSafeUnref<SkTypeface>(mTypeface);
#endif
#ifdef USE_CAIRO_SCALED_FONT
cairo_scaled_font_destroy(mScaledFont);
@ -64,16 +64,30 @@ ScaledFontBase::~ScaledFontBase()
ScaledFontBase::ScaledFontBase(const RefPtr<UnscaledFont>& aUnscaledFont,
Float aSize)
: ScaledFont(aUnscaledFont)
, mSize(aSize)
{
#ifdef USE_SKIA
mTypeface = nullptr;
, mTypeface(nullptr)
#endif
#ifdef USE_CAIRO_SCALED_FONT
mScaledFont = nullptr;
, mScaledFont(nullptr)
#endif
, mSize(aSize)
{
}
#ifdef USE_SKIA
SkTypeface*
ScaledFontBase::GetSkTypeface()
{
if (!mTypeface) {
SkTypeface* typeface = CreateSkTypeface();
if (!mTypeface.compareExchange(nullptr, typeface)) {
SkSafeUnref(typeface);
}
}
return mTypeface;
}
#endif
#ifdef USE_CAIRO_SCALED_FONT
bool
ScaledFontBase::PopulateCairoScaledFont()

Просмотреть файл

@ -42,7 +42,7 @@ public:
virtual Float GetSize() const override { return mSize; }
#ifdef USE_SKIA
virtual SkTypeface* GetSkTypeface() { return mTypeface; }
SkTypeface* GetSkTypeface();
#endif
#ifdef USE_CAIRO_SCALED_FONT
@ -54,7 +54,8 @@ public:
protected:
friend class DrawTargetSkia;
#ifdef USE_SKIA
SkTypeface* mTypeface;
Atomic<SkTypeface*> mTypeface;
virtual SkTypeface* CreateSkTypeface() { return nullptr; }
SkPath GetSkiaPathForGlyphs(const GlyphBuffer &aBuffer);
#endif
#ifdef USE_CAIRO_SCALED_FONT

Просмотреть файл

@ -172,29 +172,26 @@ ScaledFontDWrite::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget
#ifdef USE_SKIA
SkTypeface*
ScaledFontDWrite::GetSkTypeface()
ScaledFontDWrite::CreateSkTypeface()
{
if (!mTypeface) {
RefPtr<IDWriteFactory> factory = Factory::GetDWriteFactory();
if (!factory) {
return nullptr;
}
Float gamma = mGamma;
// Skia doesn't support a gamma value outside of 0-4, so default to 2.2
if (gamma < 0.0f || gamma > 4.0f) {
gamma = 2.2f;
}
Float contrast = mContrast;
// Skia doesn't support a contrast value outside of 0-1, so default to 1.0
if (contrast < 0.0f || contrast > 1.0f) {
contrast = 1.0f;
}
mTypeface = SkCreateTypefaceFromDWriteFont(factory, mFontFace, mStyle, mForceGDIMode, gamma, contrast);
RefPtr<IDWriteFactory> factory = Factory::GetDWriteFactory();
if (!factory) {
return nullptr;
}
return mTypeface;
Float gamma = mGamma;
// Skia doesn't support a gamma value outside of 0-4, so default to 2.2
if (gamma < 0.0f || gamma > 4.0f) {
gamma = 2.2f;
}
Float contrast = mContrast;
// Skia doesn't support a contrast value outside of 0-1, so default to 1.0
if (contrast < 0.0f || contrast > 1.0f) {
contrast = 1.0f;
}
return SkCreateTypefaceFromDWriteFont(factory, mFontFace, mStyle, mForceGDIMode, gamma, contrast);
}
#endif

Просмотреть файл

@ -67,7 +67,7 @@ public:
bool ForceGDIMode() { return mForceGDIMode; }
#ifdef USE_SKIA
SkTypeface* GetSkTypeface() override;
SkTypeface* CreateSkTypeface() override;
SkFontStyle mStyle;
#endif

Просмотреть файл

@ -43,13 +43,9 @@ ScaledFontFontconfig::~ScaledFontFontconfig()
}
#ifdef USE_SKIA
SkTypeface* ScaledFontFontconfig::GetSkTypeface()
SkTypeface* ScaledFontFontconfig::CreateSkTypeface()
{
if (!mTypeface) {
mTypeface = SkCreateTypefaceFromCairoFTFontWithFontconfig(mScaledFont, mPattern);
}
return mTypeface;
return SkCreateTypefaceFromCairoFTFontWithFontconfig(mScaledFont, mPattern);
}
#endif

Просмотреть файл

@ -28,7 +28,7 @@ public:
FontType GetType() const override { return FontType::FONTCONFIG; }
#ifdef USE_SKIA
SkTypeface* GetSkTypeface() override;
SkTypeface* CreateSkTypeface() override;
#endif
bool CanSerialize() override { return true; }

Просмотреть файл

@ -35,13 +35,9 @@ ScaledFontFreeType::ScaledFontFreeType(cairo_scaled_font_t* aScaledFont,
}
#ifdef USE_SKIA
SkTypeface* ScaledFontFreeType::GetSkTypeface()
SkTypeface* ScaledFontFreeType::CreateSkTypeface()
{
if (!mTypeface) {
mTypeface = SkCreateTypefaceFromCairoFTFont(mScaledFont);
}
return mTypeface;
return SkCreateTypefaceFromCairoFTFont(mScaledFont);
}
#endif

Просмотреть файл

@ -27,7 +27,7 @@ public:
FontType GetType() const override { return FontType::FREETYPE; }
#ifdef USE_SKIA
virtual SkTypeface* GetSkTypeface() override;
virtual SkTypeface* CreateSkTypeface() override;
#endif
bool CanSerialize() override { return true; }

Просмотреть файл

@ -177,21 +177,19 @@ ScaledFontMac::~ScaledFontMac()
}
#ifdef USE_SKIA
SkTypeface* ScaledFontMac::GetSkTypeface()
SkTypeface* ScaledFontMac::CreateSkTypeface()
{
if (!mTypeface) {
if (mCTFont) {
mTypeface = SkCreateTypefaceFromCTFont(mCTFont);
} else {
auto unscaledMac = static_cast<UnscaledFontMac*>(GetUnscaledFont().get());
bool dataFont = unscaledMac->IsDataFont();
CTFontRef fontFace =
CreateCTFontFromCGFontWithVariations(mFont, mSize, !dataFont);
mTypeface = SkCreateTypefaceFromCTFont(fontFace);
CFRelease(fontFace);
}
if (mCTFont) {
return SkCreateTypefaceFromCTFont(mCTFont);
} else {
auto unscaledMac = static_cast<UnscaledFontMac*>(GetUnscaledFont().get());
bool dataFont = unscaledMac->IsDataFont();
CTFontRef fontFace =
CreateCTFontFromCGFontWithVariations(mFont, mSize, !dataFont);
SkTypeface* typeface = SkCreateTypefaceFromCTFont(fontFace);
CFRelease(fontFace);
return typeface;
}
return mTypeface;
}
#endif

Просмотреть файл

@ -34,7 +34,7 @@ public:
FontType GetType() const override { return FontType::MAC; }
#ifdef USE_SKIA
SkTypeface* GetSkTypeface() override;
SkTypeface* CreateSkTypeface() override;
#endif
already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget) override;

Просмотреть файл

@ -122,12 +122,9 @@ ScaledFontWin::GetDefaultAAMode()
}
#ifdef USE_SKIA
SkTypeface* ScaledFontWin::GetSkTypeface()
SkTypeface* ScaledFontWin::CreateSkTypeface()
{
if (!mTypeface) {
mTypeface = SkCreateTypefaceFromLOGFONT(mLogFont);
}
return mTypeface;
return SkCreateTypefaceFromLOGFONT(mLogFont);
}
#endif

Просмотреть файл

@ -28,7 +28,7 @@ public:
AntialiasMode GetDefaultAAMode() override;
#ifdef USE_SKIA
SkTypeface* GetSkTypeface() override;
SkTypeface* CreateSkTypeface() override;
#endif
protected: