Bug 1376026 - fix plumbing of DWrite parameters for Skia fonts to not depend on gfxPlatform. r=jrmuizel

MozReview-Commit-ID: 5K9201eCSv
This commit is contained in:
Lee Salzman 2017-06-30 14:09:05 -04:00
parent 901f5815e8
commit ab6885d706
24 changed files with 209 additions and 244 deletions

View File

@ -1520,12 +1520,13 @@ public:
* *
* @param aData Pointer to the data * @param aData Pointer to the data
* @param aSize Size of the TrueType data * @param aSize Size of the TrueType data
* @param aType Type of NativeFontResource that should be created. * @param aBackendType Type of the reference DrawTarget the font should be created for.
* @param aFontType Type of NativeFontResource that should be created.
* @param aFontContext Optional native font context to be used to create the NativeFontResource. * @param aFontContext Optional native font context to be used to create the NativeFontResource.
* @return a NativeFontResource of nullptr if failed. * @return a NativeFontResource of nullptr if failed.
*/ */
static already_AddRefed<NativeFontResource> static already_AddRefed<NativeFontResource>
CreateNativeFontResource(uint8_t *aData, uint32_t aSize, FontType aType, void* aFontContext = nullptr); CreateNativeFontResource(uint8_t *aData, uint32_t aSize, BackendType aBackendType, FontType aFontType, void* aFontContext = nullptr);
/** /**
* This creates an unscaled font of the given type based on font descriptor * This creates an unscaled font of the given type based on font descriptor
@ -1661,16 +1662,13 @@ public:
* Returns true on success, or false on failure and leaves the D2D1/Direct3D11 devices unset. * Returns true on success, or false on failure and leaves the D2D1/Direct3D11 devices unset.
*/ */
static bool SetDirect3D11Device(ID3D11Device *aDevice); static bool SetDirect3D11Device(ID3D11Device *aDevice);
static bool SetDWriteFactory(IDWriteFactory *aFactory);
static ID3D11Device *GetDirect3D11Device(); static ID3D11Device *GetDirect3D11Device();
static ID2D1Device *GetD2D1Device(); static ID2D1Device *GetD2D1Device();
static uint32_t GetD2D1DeviceSeq(); static uint32_t GetD2D1DeviceSeq();
static IDWriteFactory *GetDWriteFactory(); static IDWriteFactory *GetDWriteFactory();
static IDWriteFactory* EnsureDWriteFactory();
static bool SupportsD2D1(); static bool SupportsD2D1();
static already_AddRefed<GlyphRenderingOptions>
CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams);
static uint64_t GetD2DVRAMUsageDrawTarget(); static uint64_t GetD2DVRAMUsageDrawTarget();
static uint64_t GetD2DVRAMUsageSourceSurface(); static uint64_t GetD2DVRAMUsageSourceSurface();
static void D2DCleanup(); static void D2DCleanup();
@ -1681,7 +1679,10 @@ public:
const RefPtr<UnscaledFont>& aUnscaledFont, const RefPtr<UnscaledFont>& aUnscaledFont,
Float aSize, Float aSize,
bool aUseEmbeddedBitmap, bool aUseEmbeddedBitmap,
bool aForceGDIMode); bool aForceGDIMode,
IDWriteRenderingParams *aParams,
Float aGamma,
Float aContrast);
static void UpdateSystemTextQuality(); static void UpdateSystemTextQuality();
@ -1689,6 +1690,8 @@ private:
static ID2D1Device *mD2D1Device; static ID2D1Device *mD2D1Device;
static ID3D11Device *mD3D11Device; static ID3D11Device *mD3D11Device;
static IDWriteFactory *mDWriteFactory; static IDWriteFactory *mDWriteFactory;
static bool mDWriteFactoryInitialized;
static Mutex* mDWriteFactoryLock;
#endif #endif
static DrawEventRecorder *mRecorder; static DrawEventRecorder *mRecorder;

View File

@ -17,6 +17,8 @@
#include "Tools.h" #include "Tools.h"
#include "nsAppRunner.h" #include "nsAppRunner.h"
#include "mozilla/Mutex.h"
using namespace std; using namespace std;
// decltype is not usable for overloaded functions. // decltype is not usable for overloaded functions.
@ -32,7 +34,6 @@ namespace gfx {
uint64_t DrawTargetD2D1::mVRAMUsageDT; uint64_t DrawTargetD2D1::mVRAMUsageDT;
uint64_t DrawTargetD2D1::mVRAMUsageSS; uint64_t DrawTargetD2D1::mVRAMUsageSS;
IDWriteFactory *DrawTargetD2D1::mDWriteFactory;
ID2D1Factory1* DrawTargetD2D1::mFactory = nullptr; ID2D1Factory1* DrawTargetD2D1::mFactory = nullptr;
ID2D1Factory1 *D2DFactory1() ID2D1Factory1 *D2DFactory1()
@ -608,7 +609,7 @@ DrawTargetD2D1::FillGlyphs(ScaledFont *aFont,
const GlyphBuffer &aBuffer, const GlyphBuffer &aBuffer,
const Pattern &aPattern, const Pattern &aPattern,
const DrawOptions &aOptions, const DrawOptions &aOptions,
const GlyphRenderingOptions *aRenderingOptions) const GlyphRenderingOptions*)
{ {
if (aFont->GetType() != FontType::DWRITE) { if (aFont->GetType() != FontType::DWRITE) {
gfxDebug() << *this << ": Ignoring drawing call for incompatible font."; gfxDebug() << *this << ": Ignoring drawing call for incompatible font.";
@ -617,16 +618,7 @@ DrawTargetD2D1::FillGlyphs(ScaledFont *aFont,
ScaledFontDWrite *font = static_cast<ScaledFontDWrite*>(aFont); ScaledFontDWrite *font = static_cast<ScaledFontDWrite*>(aFont);
IDWriteRenderingParams *params = nullptr; IDWriteRenderingParams *params = font->mParams;
if (aRenderingOptions) {
if (aRenderingOptions->GetType() != FontType::DWRITE) {
gfxDebug() << *this << ": Ignoring incompatible GlyphRenderingOptions.";
// This should never happen.
MOZ_ASSERT(false);
} else {
params = static_cast<const GlyphRenderingOptionsDWrite*>(aRenderingOptions)->mParams;
}
}
AntialiasMode aaMode = font->GetDefaultAAMode(); AntialiasMode aaMode = font->GetDefaultAAMode();
@ -1256,33 +1248,6 @@ DrawTargetD2D1::factory()
return mFactory; return mFactory;
} }
IDWriteFactory*
DrawTargetD2D1::GetDWriteFactory()
{
if (mDWriteFactory) {
return mDWriteFactory;
}
decltype(DWriteCreateFactory)* createDWriteFactory;
HMODULE dwriteModule = LoadLibraryW(L"dwrite.dll");
createDWriteFactory = (decltype(DWriteCreateFactory)*)
GetProcAddress(dwriteModule, "DWriteCreateFactory");
if (!createDWriteFactory) {
gfxWarning() << "Failed to locate DWriteCreateFactory function.";
return nullptr;
}
HRESULT hr = createDWriteFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&mDWriteFactory));
if (FAILED(hr)) {
gfxWarning() << "Failed to create DWrite Factory.";
}
return mDWriteFactory;
}
void void
DrawTargetD2D1::CleanupD2D() DrawTargetD2D1::CleanupD2D()
{ {

View File

@ -155,7 +155,6 @@ public:
static ID2D1Factory1 *factory(); static ID2D1Factory1 *factory();
static void CleanupD2D(); static void CleanupD2D();
static IDWriteFactory *GetDWriteFactory();
operator std::string() const { operator std::string() const {
std::stringstream stream; std::stringstream stream;
@ -294,7 +293,6 @@ private:
bool mDidComplexBlendWithListInList; bool mDidComplexBlendWithListInList;
static ID2D1Factory1 *mFactory; static ID2D1Factory1 *mFactory;
static IDWriteFactory *mDWriteFactory;
// This value is uesed to verify if the DrawTarget is created by a stale device. // This value is uesed to verify if the DrawTarget is created by a stale device.
uint32_t mDeviceSeq; uint32_t mDeviceSeq;

View File

@ -45,6 +45,7 @@
#include <d3d10_1.h> #include <d3d10_1.h>
#include "HelpersD2D.h" #include "HelpersD2D.h"
#include "HelpersWinFonts.h" #include "HelpersWinFonts.h"
#include "mozilla/Mutex.h"
#endif #endif
#include "DrawTargetDual.h" #include "DrawTargetDual.h"
@ -203,6 +204,8 @@ static uint32_t mDeviceSeq = 0;
ID3D11Device *Factory::mD3D11Device = nullptr; ID3D11Device *Factory::mD3D11Device = nullptr;
ID2D1Device *Factory::mD2D1Device = nullptr; ID2D1Device *Factory::mD2D1Device = nullptr;
IDWriteFactory *Factory::mDWriteFactory = nullptr; IDWriteFactory *Factory::mDWriteFactory = nullptr;
bool Factory::mDWriteFactoryInitialized = false;
Mutex* Factory::mDWriteFactoryLock = nullptr;
#endif #endif
DrawEventRecorder *Factory::mRecorder; DrawEventRecorder *Factory::mRecorder;
@ -229,6 +232,10 @@ Factory::Init(const Config& aConfig)
#ifdef MOZ_ENABLE_FREETYPE #ifdef MOZ_ENABLE_FREETYPE
mFTLock = new Mutex("Factory::mFTLock"); mFTLock = new Mutex("Factory::mFTLock");
#endif #endif
#ifdef WIN32
mDWriteFactoryLock = new Mutex("Factory::mDWriteFactoryLock");
#endif
} }
void void
@ -247,6 +254,13 @@ Factory::ShutDown()
mFTLock = nullptr; mFTLock = nullptr;
} }
#endif #endif
#ifdef WIN32
if (mDWriteFactoryLock) {
delete mDWriteFactoryLock;
mDWriteFactoryLock = nullptr;
}
#endif
} }
bool bool
@ -553,38 +567,26 @@ Factory::CreateScaledFontForNativeFont(const NativeFont &aNativeFont,
} }
already_AddRefed<NativeFontResource> already_AddRefed<NativeFontResource>
Factory::CreateNativeFontResource(uint8_t *aData, uint32_t aSize, FontType aType, void* aFontContext) Factory::CreateNativeFontResource(uint8_t *aData, uint32_t aSize, BackendType aBackendType, FontType aFontType, void* aFontContext)
{ {
switch (aType) { switch (aFontType) {
#ifdef WIN32 #ifdef WIN32
case FontType::DWRITE: case FontType::DWRITE:
{ {
return NativeFontResourceDWrite::Create(aData, aSize, bool needsCairo = aBackendType == BackendType::CAIRO ||
/* aNeedsCairo = */ false); aBackendType == BackendType::SKIA;
return NativeFontResourceDWrite::Create(aData, aSize, needsCairo);
} }
#endif case FontType::GDI:
case FontType::CAIRO: return NativeFontResourceGDI::Create(aData, aSize);
#ifdef USE_SKIA
case FontType::SKIA:
#endif
{
#ifdef WIN32
if (GetDWriteFactory()) {
return NativeFontResourceDWrite::Create(aData, aSize,
/* aNeedsCairo = */ true);
} else {
return NativeFontResourceGDI::Create(aData, aSize);
}
#elif defined(XP_DARWIN) #elif defined(XP_DARWIN)
return NativeFontResourceMac::Create(aData, aSize); case FontType::MAC:
return NativeFontResourceMac::Create(aData, aSize);
#elif defined(MOZ_WIDGET_GTK) #elif defined(MOZ_WIDGET_GTK)
return NativeFontResourceFontconfig::Create(aData, aSize, case FontType::FONTCONFIG:
static_cast<FT_Library>(aFontContext)); return NativeFontResourceFontconfig::Create(aData, aSize,
#else static_cast<FT_Library>(aFontContext));
gfxWarning() << "Unable to create cairo scaled font from truetype data";
return nullptr;
#endif #endif
}
default: default:
gfxWarning() << "Unable to create requested font resource from truetype data"; gfxWarning() << "Unable to create requested font resource from truetype data";
return nullptr; return nullptr;
@ -756,13 +758,6 @@ Factory::CreateDrawTargetForD3D11Texture(ID3D11Texture2D *aTexture, SurfaceForma
return nullptr; return nullptr;
} }
bool
Factory::SetDWriteFactory(IDWriteFactory *aFactory)
{
mDWriteFactory = aFactory;
return true;
}
bool bool
Factory::SetDirect3D11Device(ID3D11Device *aDevice) Factory::SetDirect3D11Device(ID3D11Device *aDevice)
{ {
@ -818,18 +813,43 @@ Factory::GetDWriteFactory()
return mDWriteFactory; return mDWriteFactory;
} }
IDWriteFactory*
Factory::EnsureDWriteFactory()
{
MOZ_ASSERT(mDWriteFactoryLock);
MutexAutoLock lock(*mDWriteFactoryLock);
if (mDWriteFactoryInitialized) {
return mDWriteFactory;
}
mDWriteFactoryInitialized = true;
HMODULE dwriteModule = LoadLibraryW(L"dwrite.dll");
decltype(DWriteCreateFactory)* createDWriteFactory = (decltype(DWriteCreateFactory)*)
GetProcAddress(dwriteModule, "DWriteCreateFactory");
if (!createDWriteFactory) {
gfxWarning() << "Failed to locate DWriteCreateFactory function.";
return nullptr;
}
HRESULT hr = createDWriteFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(&mDWriteFactory));
if (FAILED(hr)) {
gfxWarning() << "Failed to create DWrite Factory.";
}
return mDWriteFactory;
}
bool bool
Factory::SupportsD2D1() Factory::SupportsD2D1()
{ {
return !!D2DFactory1(); return !!D2DFactory1();
} }
already_AddRefed<GlyphRenderingOptions>
Factory::CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams)
{
return MakeAndAddRef<GlyphRenderingOptionsDWrite>(aParams);
}
BYTE sSystemTextQuality = CLEARTYPE_QUALITY; BYTE sSystemTextQuality = CLEARTYPE_QUALITY;
void void
Factory::UpdateSystemTextQuality() Factory::UpdateSystemTextQuality()
@ -867,10 +887,14 @@ Factory::CreateScaledFontForDWriteFont(IDWriteFontFace* aFontFace,
const RefPtr<UnscaledFont>& aUnscaledFont, const RefPtr<UnscaledFont>& aUnscaledFont,
float aSize, float aSize,
bool aUseEmbeddedBitmap, bool aUseEmbeddedBitmap,
bool aForceGDIMode) bool aForceGDIMode,
IDWriteRenderingParams* aParams,
Float aGamma,
Float aContrast)
{ {
return MakeAndAddRef<ScaledFontDWrite>(aFontFace, aUnscaledFont, aSize, return MakeAndAddRef<ScaledFontDWrite>(aFontFace, aUnscaledFont, aSize,
aUseEmbeddedBitmap, aForceGDIMode, aUseEmbeddedBitmap, aForceGDIMode,
aParams, aGamma, aContrast,
aStyle); aStyle);
} }

View File

@ -102,20 +102,5 @@ InlineTranslator::CreateDrawTarget(ReferencePtr aRefPtr,
return drawTarget.forget(); return drawTarget.forget();
} }
FontType
InlineTranslator::GetDesiredFontType()
{
switch (mBaseDT->GetBackendType()) {
case BackendType::DIRECT2D:
return FontType::DWRITE;
case BackendType::CAIRO:
return FontType::CAIRO;
case BackendType::SKIA:
return FontType::SKIA;
default:
return FontType::CAIRO;
}
}
} // namespace gfx } // namespace gfx
} // namespace mozilla } // namespace mozilla

View File

@ -173,8 +173,6 @@ public:
mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final { return mBaseDT; } mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final { return mBaseDT; }
mozilla::gfx::FontType GetDesiredFontType() final;
void* GetFontContext() final { return mFontContext; } void* GetFontContext() final { return mFontContext; }
private: private:

View File

@ -9,7 +9,6 @@
#include <unordered_map> #include <unordered_map>
#include "DrawTargetD2D1.h"
#include "Logging.h" #include "Logging.h"
#include "mozilla/RefPtr.h" #include "mozilla/RefPtr.h"
@ -70,7 +69,7 @@ public:
{ {
if (!mInstance) { if (!mInstance) {
mInstance = new DWriteFontFileLoader(); mInstance = new DWriteFontFileLoader();
DrawTargetD2D1::GetDWriteFactory()-> Factory::GetDWriteFactory()->
RegisterFontFileLoader(mInstance); RegisterFontFileLoader(mInstance);
} }
return mInstance; return mInstance;
@ -222,7 +221,7 @@ already_AddRefed<NativeFontResourceDWrite>
NativeFontResourceDWrite::Create(uint8_t *aFontData, uint32_t aDataLength, NativeFontResourceDWrite::Create(uint8_t *aFontData, uint32_t aDataLength,
bool aNeedsCairo) bool aNeedsCairo)
{ {
IDWriteFactory *factory = DrawTargetD2D1::GetDWriteFactory(); IDWriteFactory *factory = Factory::EnsureDWriteFactory();
if (!factory) { if (!factory) {
gfxWarning() << "Failed to get DWrite Factory."; gfxWarning() << "Failed to get DWrite Factory.";
return nullptr; return nullptr;

View File

@ -24,7 +24,7 @@ const uint32_t kMagicInt = 0xc001feed;
// loss of backwards compatibility. Old streams will not work in a player // loss of backwards compatibility. Old streams will not work in a player
// using a newer major revision. And new streams will not work in a player // using a newer major revision. And new streams will not work in a player
// using an older major revision. // using an older major revision.
const uint16_t kMajorRevision = 9; const uint16_t kMajorRevision = 10;
// A change in minor revision means additions of new events. New streams will // A change in minor revision means additions of new events. New streams will
// not play in older players. // not play in older players.
const uint16_t kMinorRevision = 0; const uint16_t kMinorRevision = 0;
@ -111,7 +111,6 @@ public:
const IntSize &aSize, const IntSize &aSize,
SurfaceFormat aFormat); SurfaceFormat aFormat);
virtual DrawTarget *GetReferenceDrawTarget() = 0; virtual DrawTarget *GetReferenceDrawTarget() = 0;
virtual FontType GetDesiredFontType() = 0;
virtual void* GetFontContext() { return nullptr; } virtual void* GetFontContext() { return nullptr; }
}; };

View File

@ -877,7 +877,9 @@ public:
} }
explicit RecordedFontData(UnscaledFont *aUnscaledFont) explicit RecordedFontData(UnscaledFont *aUnscaledFont)
: RecordedEventDerived(FONTDATA), mData(nullptr) : RecordedEventDerived(FONTDATA)
, mType(aUnscaledFont->GetType())
, mData(nullptr)
{ {
mGetFontFileDataSucceeded = aUnscaledFont->GetFontFileData(&FontDataProc, this); mGetFontFileDataSucceeded = aUnscaledFont->GetFontFileData(&FontDataProc, this);
} }
@ -901,6 +903,7 @@ public:
private: private:
friend class RecordedEvent; friend class RecordedEvent;
FontType mType;
uint8_t* mData; uint8_t* mData;
RecordedFontDetails mFontDetails; RecordedFontDetails mFontDetails;
@ -2683,8 +2686,8 @@ RecordedFontData::PlayEvent(Translator *aTranslator) const
{ {
RefPtr<NativeFontResource> fontResource = RefPtr<NativeFontResource> fontResource =
Factory::CreateNativeFontResource(mData, mFontDetails.size, Factory::CreateNativeFontResource(mData, mFontDetails.size,
aTranslator->GetDesiredFontType(), aTranslator->GetReferenceDrawTarget()->GetBackendType(),
aTranslator->GetFontContext()); mType, aTranslator->GetFontContext());
if (!fontResource) { if (!fontResource) {
return false; return false;
} }
@ -2699,6 +2702,7 @@ RecordedFontData::Record(S &aStream) const
{ {
MOZ_ASSERT(mGetFontFileDataSucceeded); MOZ_ASSERT(mGetFontFileDataSucceeded);
WriteElement(aStream, mType);
WriteElement(aStream, mFontDetails.fontDataKey); WriteElement(aStream, mFontDetails.fontDataKey);
WriteElement(aStream, mFontDetails.size); WriteElement(aStream, mFontDetails.size);
aStream.write((const char*)mData, mFontDetails.size); aStream.write((const char*)mData, mFontDetails.size);
@ -2737,8 +2741,10 @@ RecordedFontData::GetFontDetails(RecordedFontDetails& fontDetails)
template<class S> template<class S>
RecordedFontData::RecordedFontData(S &aStream) RecordedFontData::RecordedFontData(S &aStream)
: RecordedEventDerived(FONTDATA) : RecordedEventDerived(FONTDATA)
, mType(FontType::SKIA)
, mData(nullptr) , mData(nullptr)
{ {
ReadElement(aStream, mType);
ReadElement(aStream, mFontDetails.fontDataKey); ReadElement(aStream, mFontDetails.fontDataKey);
ReadElement(aStream, mFontDetails.size); ReadElement(aStream, mFontDetails.size);
mData = new uint8_t[mFontDetails.size]; mData = new uint8_t[mFontDetails.size];

View File

@ -3,11 +3,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DrawTargetD2D1.h"
#include "ScaledFontDWrite.h" #include "ScaledFontDWrite.h"
#include "UnscaledFontDWrite.h" #include "UnscaledFontDWrite.h"
#include "PathD2D.h" #include "PathD2D.h"
#include "gfxFont.h" #include "gfxFont.h"
#include "Logging.h"
using namespace std; using namespace std;
@ -108,16 +108,24 @@ ScaledFontDWrite::ScaledFontDWrite(IDWriteFontFace *aFontFace,
Float aSize, Float aSize,
bool aUseEmbeddedBitmap, bool aUseEmbeddedBitmap,
bool aForceGDIMode, bool aForceGDIMode,
IDWriteRenderingParams* aParams,
Float aGamma,
Float aContrast,
const gfxFontStyle* aStyle) const gfxFontStyle* aStyle)
: ScaledFontBase(aUnscaledFont, aSize) : ScaledFontBase(aUnscaledFont, aSize)
, mFontFace(aFontFace) , mFontFace(aFontFace)
, mUseEmbeddedBitmap(aUseEmbeddedBitmap) , mUseEmbeddedBitmap(aUseEmbeddedBitmap)
, mForceGDIMode(aForceGDIMode) , mForceGDIMode(aForceGDIMode)
, mParams(aParams)
, mGamma(aGamma)
, mContrast(aContrast)
{ {
mStyle = SkFontStyle(aStyle->weight, if (aStyle) {
DWriteFontStretchFromStretch(aStyle->stretch), mStyle = SkFontStyle(aStyle->weight,
aStyle->style == NS_FONT_STYLE_NORMAL ? DWriteFontStretchFromStretch(aStyle->stretch),
SkFontStyle::kUpright_Slant : SkFontStyle::kItalic_Slant); aStyle->style == NS_FONT_STYLE_NORMAL ?
SkFontStyle::kUpright_Slant : SkFontStyle::kItalic_Slant);
}
} }
already_AddRefed<Path> already_AddRefed<Path>
@ -143,12 +151,12 @@ SkTypeface*
ScaledFontDWrite::GetSkTypeface() ScaledFontDWrite::GetSkTypeface()
{ {
if (!mTypeface) { if (!mTypeface) {
IDWriteFactory *factory = DrawTargetD2D1::GetDWriteFactory(); IDWriteFactory *factory = Factory::GetDWriteFactory();
if (!factory) { if (!factory) {
return nullptr; return nullptr;
} }
mTypeface = SkCreateTypefaceFromDWriteFont(factory, mFontFace, mStyle, mForceGDIMode); mTypeface = SkCreateTypefaceFromDWriteFont(factory, mFontFace, mStyle, mForceGDIMode, mGamma, mContrast);
} }
return mTypeface; return mTypeface;
} }
@ -272,12 +280,34 @@ UnscaledFontDWrite::GetFontFileData(FontFileDataOutput aDataCallback, void *aBat
return true; return true;
} }
bool
ScaledFontDWrite::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
{
InstanceData instance(this);
aCb(reinterpret_cast<uint8_t*>(&instance), sizeof(instance), aBaton);
return true;
}
already_AddRefed<ScaledFont> already_AddRefed<ScaledFont>
UnscaledFontDWrite::CreateScaledFont(Float aGlyphSize, UnscaledFontDWrite::CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData, const uint8_t* aInstanceData,
uint32_t aInstanceDataLength) uint32_t aInstanceDataLength)
{ {
RefPtr<ScaledFontBase> scaledFont = new ScaledFontDWrite(mFontFace, this, aGlyphSize); if (aInstanceDataLength < sizeof(ScaledFontDWrite::InstanceData)) {
gfxWarning() << "DWrite scaled font instance data is truncated.";
return nullptr;
}
const ScaledFontDWrite::InstanceData *instanceData =
reinterpret_cast<const ScaledFontDWrite::InstanceData*>(aInstanceData);
RefPtr<ScaledFontBase> scaledFont =
new ScaledFontDWrite(mFontFace, this, aGlyphSize,
instanceData->mUseEmbeddedBitmap,
instanceData->mForceGDIMode,
nullptr,
instanceData->mGamma,
instanceData->mContrast);
if (mNeedsCairo && !scaledFont->PopulateCairoScaledFont()) { if (mNeedsCairo && !scaledFont->PopulateCairoScaledFont()) {
gfxWarning() << "Unable to create cairo scaled font DWrite font."; gfxWarning() << "Unable to create cairo scaled font DWrite font.";
return nullptr; return nullptr;

View File

@ -15,6 +15,9 @@ struct gfxFontStyle;
namespace mozilla { namespace mozilla {
namespace gfx { namespace gfx {
class NativeFontResourceDWrite;
class UnscaledFontDWrite;
class ScaledFontDWrite final : public ScaledFontBase class ScaledFontDWrite final : public ScaledFontBase
{ {
public: public:
@ -26,6 +29,8 @@ public:
, mFontFace(aFont) , mFontFace(aFont)
, mUseEmbeddedBitmap(false) , mUseEmbeddedBitmap(false)
, mForceGDIMode(false) , mForceGDIMode(false)
, mGamma(2.2f)
, mContrast(1.0f)
{} {}
ScaledFontDWrite(IDWriteFontFace *aFontFace, ScaledFontDWrite(IDWriteFontFace *aFontFace,
@ -33,7 +38,10 @@ public:
Float aSize, Float aSize,
bool aUseEmbeddedBitmap, bool aUseEmbeddedBitmap,
bool aForceGDIMode, bool aForceGDIMode,
const gfxFontStyle* aStyle); IDWriteRenderingParams *aParams,
Float aContrast,
Float aGamma,
const gfxFontStyle* aStyle = nullptr);
FontType GetType() const override { return FontType::DWRITE; } FontType GetType() const override { return FontType::DWRITE; }
@ -46,6 +54,8 @@ public:
bool CanSerialize() override { return true; } bool CanSerialize() override { return true; }
bool GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton) override;
AntialiasMode GetDefaultAAMode() override; AntialiasMode GetDefaultAAMode() override;
bool UseEmbeddedBitmaps() { return mUseEmbeddedBitmap; } bool UseEmbeddedBitmaps() { return mUseEmbeddedBitmap; }
@ -59,29 +69,39 @@ public:
RefPtr<IDWriteFontFace> mFontFace; RefPtr<IDWriteFontFace> mFontFace;
bool mUseEmbeddedBitmap; bool mUseEmbeddedBitmap;
bool mForceGDIMode; bool mForceGDIMode;
// DrawTargetD2D1 requires the IDWriteRenderingParams,
// but we also separately need to store the gamma and contrast
// since Skia needs to be able to access these without having
// to use the full set of DWrite parameters (which would be
// required to recreate an IDWriteRenderingParams) in a
// DrawTargetRecording playback.
RefPtr<IDWriteRenderingParams> mParams;
Float mGamma;
Float mContrast;
protected: protected:
#ifdef USE_CAIRO_SCALED_FONT #ifdef USE_CAIRO_SCALED_FONT
cairo_font_face_t* GetCairoFontFace() override; cairo_font_face_t* GetCairoFontFace() override;
#endif #endif
};
class GlyphRenderingOptionsDWrite : public GlyphRenderingOptions
{
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GlyphRenderingOptionsDWrite, override)
explicit GlyphRenderingOptionsDWrite(IDWriteRenderingParams *aParams)
: mParams(aParams)
{
}
FontType GetType() const override { return FontType::DWRITE; }
private: private:
friend class DrawTargetD2D; friend class NativeFontResourceDWrite;
friend class DrawTargetD2D1; friend class UnscaledFontDWrite;
RefPtr<IDWriteRenderingParams> mParams; struct InstanceData
{
explicit InstanceData(ScaledFontDWrite* aScaledFont)
: mUseEmbeddedBitmap(aScaledFont->mUseEmbeddedBitmap)
, mForceGDIMode(aScaledFont->mForceGDIMode)
, mGamma(aScaledFont->mGamma)
, mContrast(aScaledFont->mContrast)
{}
bool mUseEmbeddedBitmap;
bool mForceGDIMode;
Float mGamma;
Float mContrast;
};
}; };
} }

View File

@ -53,7 +53,9 @@ struct IDWriteFontFallback;
SK_API SkTypeface* SkCreateTypefaceFromDWriteFont(IDWriteFactory* aFactory, SK_API SkTypeface* SkCreateTypefaceFromDWriteFont(IDWriteFactory* aFactory,
IDWriteFontFace* aFontFace, IDWriteFontFace* aFontFace,
SkFontStyle aStyle, SkFontStyle aStyle,
bool aForceGDI); bool aForceGDI,
float aGamma,
float aContrast);
SK_API sk_sp<SkFontMgr> SkFontMgr_New_GDI(); SK_API sk_sp<SkFontMgr> SkFontMgr_New_GDI();
SK_API sk_sp<SkFontMgr> SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL, SK_API sk_sp<SkFontMgr> SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL,

View File

@ -341,9 +341,11 @@ SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT& origLF) {
SkTypeface* SkCreateTypefaceFromDWriteFont(IDWriteFactory* aFactory, SkTypeface* SkCreateTypefaceFromDWriteFont(IDWriteFactory* aFactory,
IDWriteFontFace* aFontFace, IDWriteFontFace* aFontFace,
SkFontStyle aStyle, SkFontStyle aStyle,
bool aForceGDI) bool aForceGDI,
float aGamma,
float aContrast)
{ {
return DWriteFontTypeface::Create(aFactory, aFontFace, aStyle, aForceGDI); return DWriteFontTypeface::Create(aFactory, aFontFace, aStyle, aForceGDI, aGamma, aContrast);
} }
/** /**

View File

@ -251,10 +251,6 @@ SkScalerContext* DWriteFontTypeface::onCreateScalerContext(const SkScalerContext
return new SkScalerContext_DW(sk_ref_sp(const_cast<DWriteFontTypeface*>(this)), effects, desc); return new SkScalerContext_DW(sk_ref_sp(const_cast<DWriteFontTypeface*>(this)), effects, desc);
} }
#ifdef MOZ_SKIA
IDWriteRenderingParams* GetDwriteRenderingParams(bool aGDI);
#endif
void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const { void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const {
if (rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) { if (rec->fFlags & SkScalerContext::kLCD_Vertical_Flag) {
rec->fMaskFormat = SkMask::kA8_Format; rec->fMaskFormat = SkMask::kA8_Format;
@ -288,13 +284,11 @@ void DWriteFontTypeface::onFilterRec(SkScalerContext::Rec* rec) const {
} }
} }
#elif defined(MOZ_SKIA) #elif defined(MOZ_SKIA)
IDWriteRenderingParams* params = GetDwriteRenderingParams(ForceGDI()); rec->setContrast(fContrast);
SkASSERT(params);
rec->setContrast(params->GetEnhancedContrast());
// GDI gamma should be 2.3 // GDI gamma should be 2.3
// See the LUT gamma values comment for GDI fonts. // See the LUT gamma values comment for GDI fonts.
float gamma = ForceGDI() ? 2.3f : params->GetGamma(); float gamma = ForceGDI() ? 2.3f : fGamma;
rec->setDeviceGamma(gamma); rec->setDeviceGamma(gamma);
rec->setPaintGamma(gamma); rec->setPaintGamma(gamma);
#endif #endif

View File

@ -53,6 +53,8 @@ private:
, fDWriteFont(SkSafeRefComPtr(font)) , fDWriteFont(SkSafeRefComPtr(font))
, fDWriteFontFace(SkRefComPtr(fontFace)) , fDWriteFontFace(SkRefComPtr(fontFace))
, fForceGDI(false) , fForceGDI(false)
, fGamma(2.2f)
, fContrast(1.0f)
{ {
if (!SUCCEEDED(fDWriteFontFace->QueryInterface(&fDWriteFontFace1))) { if (!SUCCEEDED(fDWriteFontFace->QueryInterface(&fDWriteFontFace1))) {
// IUnknown::QueryInterface states that if it fails, punk will be set to nullptr. // IUnknown::QueryInterface states that if it fails, punk will be set to nullptr.
@ -81,12 +83,16 @@ public:
static DWriteFontTypeface* Create(IDWriteFactory* factory, static DWriteFontTypeface* Create(IDWriteFactory* factory,
IDWriteFontFace* fontFace, IDWriteFontFace* fontFace,
SkFontStyle aStyle, SkFontStyle aStyle,
bool aForceGDI) { bool aForceGDI,
float aGamma,
float aContrast) {
DWriteFontTypeface* typeface = DWriteFontTypeface* typeface =
new DWriteFontTypeface(aStyle, factory, fontFace, new DWriteFontTypeface(aStyle, factory, fontFace,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr); nullptr, nullptr);
typeface->fForceGDI = aForceGDI; typeface->fForceGDI = aForceGDI;
typeface->fGamma = aGamma;
typeface->fContrast = aContrast;
return typeface; return typeface;
} }
@ -139,6 +145,8 @@ protected:
private: private:
typedef SkTypeface INHERITED; typedef SkTypeface INHERITED;
bool fForceGDI; bool fForceGDI;
float fGamma;
float fContrast;
}; };
#endif #endif

View File

@ -158,7 +158,7 @@ gfxDWriteFontFileLoader::CreateCustomFontFile(FallibleTArray<uint8_t>& aFontData
MOZ_ASSERT(aFontFile); MOZ_ASSERT(aFontFile);
MOZ_ASSERT(aFontFileStream); MOZ_ASSERT(aFontFileStream);
IDWriteFactory *factory = gfxWindowsPlatform::GetPlatform()->GetDWriteFactory(); IDWriteFactory *factory = mozilla::gfx::Factory::GetDWriteFactory();
if (!factory) { if (!factory) {
gfxCriticalError() << "Failed to get DWrite Factory in CreateCustomFontFile."; gfxCriticalError() << "Failed to get DWrite Factory in CreateCustomFontFile.";
return E_FAIL; return E_FAIL;

View File

@ -127,7 +127,7 @@ public:
{ {
if (!mInstance) { if (!mInstance) {
mInstance = new gfxDWriteFontFileLoader(); mInstance = new gfxDWriteFontFileLoader();
gfxWindowsPlatform::GetPlatform()->GetDWriteFactory()-> mozilla::gfx::Factory::GetDWriteFactory()->
RegisterFontFileLoader(mInstance); RegisterFontFileLoader(mInstance);
} }
return mInstance; return mInstance;

View File

@ -613,7 +613,7 @@ gfxDWriteFontEntry::CreateFontFace(IDWriteFontFace **aFontFace,
hr = mFont->CreateFontFace(getter_AddRefs(mFontFace)); hr = mFont->CreateFontFace(getter_AddRefs(mFontFace));
} else if (mFontFile) { } else if (mFontFile) {
IDWriteFontFile *fontFile = mFontFile.get(); IDWriteFontFile *fontFile = mFontFile.get();
hr = gfxWindowsPlatform::GetPlatform()->GetDWriteFactory()-> hr = Factory::GetDWriteFactory()->
CreateFontFace(mFaceType, CreateFontFace(mFaceType,
1, 1,
&fontFile, &fontFile,
@ -644,7 +644,7 @@ gfxDWriteFontEntry::CreateFontFace(IDWriteFontFace **aFontFace,
if (FAILED(mFontFace->GetFiles(&numberOfFiles, files.Elements()))) { if (FAILED(mFontFace->GetFiles(&numberOfFiles, files.Elements()))) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
HRESULT hr = gfxWindowsPlatform::GetPlatform()->GetDWriteFactory()-> HRESULT hr = Factory::GetDWriteFactory()->
CreateFontFace(mFontFace->GetType(), CreateFontFace(mFontFace->GetType(),
numberOfFiles, numberOfFiles,
files.Elements(), files.Elements(),
@ -883,7 +883,7 @@ gfxDWriteFontList::InitFontListForPlatform()
mFontSubstitutes.Clear(); mFontSubstitutes.Clear();
mNonExistingFonts.Clear(); mNonExistingFonts.Clear();
hr = gfxWindowsPlatform::GetPlatform()->GetDWriteFactory()-> hr = Factory::GetDWriteFactory()->
GetGdiInterop(getter_AddRefs(mGDIInterop)); GetGdiInterop(getter_AddRefs(mGDIInterop));
if (FAILED(hr)) { if (FAILED(hr)) {
Telemetry::Accumulate(Telemetry::DWRITEFONT_INIT_PROBLEM, Telemetry::Accumulate(Telemetry::DWRITEFONT_INIT_PROBLEM,
@ -894,7 +894,7 @@ gfxDWriteFontList::InitFontListForPlatform()
QueryPerformanceCounter(&t2); // base-class/interop initialization QueryPerformanceCounter(&t2); // base-class/interop initialization
RefPtr<IDWriteFactory> factory = RefPtr<IDWriteFactory> factory =
gfxWindowsPlatform::GetPlatform()->GetDWriteFactory(); Factory::GetDWriteFactory();
hr = factory->GetSystemFontCollection(getter_AddRefs(mSystemFonts)); hr = factory->GetSystemFontCollection(getter_AddRefs(mSystemFonts));
NS_ASSERTION(SUCCEEDED(hr), "GetSystemFontCollection failed!"); NS_ASSERTION(SUCCEEDED(hr), "GetSystemFontCollection failed!");
@ -1425,7 +1425,7 @@ gfxDWriteFontList::GlobalFontFallback(const uint32_t aCh,
HRESULT hr; HRESULT hr;
RefPtr<IDWriteFactory> dwFactory = RefPtr<IDWriteFactory> dwFactory =
gfxWindowsPlatform::GetPlatform()->GetDWriteFactory(); Factory::GetDWriteFactory();
if (!dwFactory) { if (!dwFactory) {
return nullptr; return nullptr;
} }

View File

@ -599,19 +599,6 @@ gfxDWriteFont::GetGlyphWidth(DrawTarget& aDrawTarget, uint16_t aGID)
return width; return width;
} }
already_AddRefed<GlyphRenderingOptions>
gfxDWriteFont::GetGlyphRenderingOptions(const TextRunDrawParams* aRunParams)
{
if (mUseClearType) {
return Factory::CreateDWriteGlyphRenderingOptions(
gfxWindowsPlatform::GetPlatform()->GetRenderingParams(GetForceGDIClassic() ?
gfxWindowsPlatform::TEXT_RENDERING_GDI_CLASSIC : gfxWindowsPlatform::TEXT_RENDERING_NORMAL));
} else {
return Factory::CreateDWriteGlyphRenderingOptions(gfxWindowsPlatform::GetPlatform()->
GetRenderingParams(gfxWindowsPlatform::TEXT_RENDERING_NO_CLEARTYPE));
}
}
bool bool
gfxDWriteFont::GetForceGDIClassic() gfxDWriteFont::GetForceGDIClassic()
{ {
@ -707,10 +694,17 @@ gfxDWriteFont::GetScaledFont(mozilla::gfx::DrawTarget *aTarget)
GetUnscaledFont(), GetUnscaledFont(),
GetAdjustedSize(), GetAdjustedSize(),
GetCairoScaledFont()); GetCairoScaledFont());
} else if (aTarget->GetBackendType() == BackendType::SKIA) { } else {
gfxDWriteFontEntry *fe = gfxDWriteFontEntry *fe =
static_cast<gfxDWriteFontEntry*>(mFontEntry.get()); static_cast<gfxDWriteFontEntry*>(mFontEntry.get());
bool useEmbeddedBitmap = (fe->IsCJKFont() && HasBitmapStrikeForSize(NS_lround(mAdjustedSize))); bool useEmbeddedBitmap = (fe->IsCJKFont() && HasBitmapStrikeForSize(NS_lround(mAdjustedSize)));
bool forceGDI = GetForceGDIClassic();
IDWriteRenderingParams* params = gfxWindowsPlatform::GetPlatform()->GetRenderingParams(
mUseClearType ?
(forceGDI ?
gfxWindowsPlatform::TEXT_RENDERING_GDI_CLASSIC : gfxWindowsPlatform::TEXT_RENDERING_NORMAL) :
gfxWindowsPlatform::TEXT_RENDERING_NO_CLEARTYPE);
const gfxFontStyle* fontStyle = GetStyle(); const gfxFontStyle* fontStyle = GetStyle();
mAzureScaledFont = mAzureScaledFont =
@ -718,11 +712,10 @@ gfxDWriteFont::GetScaledFont(mozilla::gfx::DrawTarget *aTarget)
GetUnscaledFont(), GetUnscaledFont(),
GetAdjustedSize(), GetAdjustedSize(),
useEmbeddedBitmap, useEmbeddedBitmap,
GetForceGDIClassic()); forceGDI,
} else { params,
mAzureScaledFont = Factory::CreateScaledFontForNativeFont(nativeFont, params->GetGamma(),
GetUnscaledFont(), params->GetEnhancedContrast());
GetAdjustedSize());
} }
mAzureScaledFontIsCairo = wantCairo; mAzureScaledFontIsCairo = wantCairo;

View File

@ -61,9 +61,6 @@ public:
virtual int32_t GetGlyphWidth(DrawTarget& aDrawTarget, virtual int32_t GetGlyphWidth(DrawTarget& aDrawTarget,
uint16_t aGID) override; uint16_t aGID) override;
virtual already_AddRefed<mozilla::gfx::GlyphRenderingOptions>
GetGlyphRenderingOptions(const TextRunDrawParams* aRunParams = nullptr) override;
virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
FontCacheSizes* aSizes) const override; FontCacheSizes* aSizes) const override;
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,

View File

@ -80,14 +80,6 @@ using namespace mozilla::layers;
using namespace mozilla::widget; using namespace mozilla::widget;
using namespace mozilla::image; using namespace mozilla::image;
IDWriteRenderingParams* GetDwriteRenderingParams(bool aGDI)
{
gfxWindowsPlatform::TextRenderingMode mode = aGDI ?
gfxWindowsPlatform::TEXT_RENDERING_GDI_CLASSIC :
gfxWindowsPlatform::TEXT_RENDERING_NORMAL;
return gfxWindowsPlatform::GetPlatform()->GetRenderingParams(mode);
}
DCFromDrawTarget::DCFromDrawTarget(DrawTarget& aDrawTarget) DCFromDrawTarget::DCFromDrawTarget(DrawTarget& aDrawTarget)
{ {
mDC = nullptr; mDC = nullptr;
@ -363,7 +355,7 @@ gfxWindowsPlatform::InitAcceleration()
UpdateRenderMode(); UpdateRenderMode();
// If we have Skia and we didn't init dwrite already, do it now. // If we have Skia and we didn't init dwrite already, do it now.
if (!mDWriteFactory && GetDefaultContentBackend() == BackendType::SKIA) { if (!DWriteEnabled() && GetDefaultContentBackend() == BackendType::SKIA) {
InitDWriteSupport(); InitDWriteSupport();
} }
@ -389,26 +381,10 @@ bool
gfxWindowsPlatform::InitDWriteSupport() gfxWindowsPlatform::InitDWriteSupport()
{ {
mozilla::ScopedGfxFeatureReporter reporter("DWrite"); mozilla::ScopedGfxFeatureReporter reporter("DWrite");
decltype(DWriteCreateFactory)* createDWriteFactory = (decltype(DWriteCreateFactory)*) if (!Factory::EnsureDWriteFactory()) {
GetProcAddress(LoadLibraryW(L"dwrite.dll"), "DWriteCreateFactory");
if (!createDWriteFactory) {
return false; return false;
} }
// I need a direct pointer to be able to cast to IUnknown**, I also need to
// remember to release this because the nsRefPtr will AddRef it.
RefPtr<IDWriteFactory> factory;
HRESULT hr = createDWriteFactory(
DWRITE_FACTORY_TYPE_SHARED,
__uuidof(IDWriteFactory),
(IUnknown **)((IDWriteFactory **)getter_AddRefs(factory)));
if (FAILED(hr) || !factory) {
return false;
}
mDWriteFactory = factory;
Factory::SetDWriteFactory(mDWriteFactory);
SetupClearTypeParams(); SetupClearTypeParams();
reporter.SetSuccessful(); reporter.SetSuccessful();
return true; return true;
@ -515,7 +491,7 @@ gfxWindowsPlatform::CreatePlatformFontList()
// bug 630201 - older pre-RTM versions of Direct2D/DirectWrite cause odd // bug 630201 - older pre-RTM versions of Direct2D/DirectWrite cause odd
// crashers so blacklist them altogether // crashers so blacklist them altogether
if (IsNotWin7PreRTM() && GetDWriteFactory()) { if (IsNotWin7PreRTM() && DWriteEnabled()) {
pfl = new gfxDWriteFontList(); pfl = new gfxDWriteFontList();
if (NS_SUCCEEDED(pfl->InitFontList())) { if (NS_SUCCEEDED(pfl->InitFontList())) {
return pfl; return pfl;
@ -579,22 +555,7 @@ already_AddRefed<ScaledFont>
gfxWindowsPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont) gfxWindowsPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
{ {
if (aFont->GetType() == gfxFont::FONT_TYPE_DWRITE) { if (aFont->GetType() == gfxFont::FONT_TYPE_DWRITE) {
gfxDWriteFont *font = static_cast<gfxDWriteFont*>(aFont); return aFont->GetScaledFont(aTarget);
NativeFont nativeFont;
nativeFont.mType = NativeFontType::DWRITE_FONT_FACE;
nativeFont.mFont = font->GetFontFace();
if (aTarget->GetBackendType() == BackendType::CAIRO) {
return Factory::CreateScaledFontWithCairo(nativeFont,
font->GetUnscaledFont(),
font->GetAdjustedSize(),
font->GetCairoScaledFont());
}
return Factory::CreateScaledFontForNativeFont(nativeFont,
font->GetUnscaledFont(),
font->GetAdjustedSize());
} }
NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_GDI, NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_GDI,
@ -1142,7 +1103,7 @@ gfxWindowsPlatform::FontsPrefsChanged(const char *aPref)
void void
gfxWindowsPlatform::SetupClearTypeParams() gfxWindowsPlatform::SetupClearTypeParams()
{ {
if (GetDWriteFactory()) { if (DWriteEnabled()) {
// any missing prefs will default to invalid (-1) and be ignored; // any missing prefs will default to invalid (-1) and be ignored;
// out-of-range values will also be ignored // out-of-range values will also be ignored
FLOAT gamma = -1.0; FLOAT gamma = -1.0;
@ -1197,7 +1158,7 @@ gfxWindowsPlatform::SetupClearTypeParams()
} }
RefPtr<IDWriteRenderingParams> defaultRenderingParams; RefPtr<IDWriteRenderingParams> defaultRenderingParams;
GetDWriteFactory()->CreateRenderingParams(getter_AddRefs(defaultRenderingParams)); Factory::GetDWriteFactory()->CreateRenderingParams(getter_AddRefs(defaultRenderingParams));
// For EnhancedContrast, we override the default if the user has not set it // For EnhancedContrast, we override the default if the user has not set it
// in the registry (by using the ClearType Tuner). // in the registry (by using the ClearType Tuner).
if (contrast < 0.0 || contrast > 10.0) { if (contrast < 0.0 || contrast > 10.0) {
@ -1253,14 +1214,14 @@ gfxWindowsPlatform::SetupClearTypeParams()
mRenderingParams[TEXT_RENDERING_NO_CLEARTYPE] = defaultRenderingParams; mRenderingParams[TEXT_RENDERING_NO_CLEARTYPE] = defaultRenderingParams;
HRESULT hr = GetDWriteFactory()->CreateCustomRenderingParams( HRESULT hr = Factory::GetDWriteFactory()->CreateCustomRenderingParams(
gamma, contrast, level, dwriteGeometry, renderMode, gamma, contrast, level, dwriteGeometry, renderMode,
getter_AddRefs(mRenderingParams[TEXT_RENDERING_NORMAL])); getter_AddRefs(mRenderingParams[TEXT_RENDERING_NORMAL]));
if (FAILED(hr) || !mRenderingParams[TEXT_RENDERING_NORMAL]) { if (FAILED(hr) || !mRenderingParams[TEXT_RENDERING_NORMAL]) {
mRenderingParams[TEXT_RENDERING_NORMAL] = defaultRenderingParams; mRenderingParams[TEXT_RENDERING_NORMAL] = defaultRenderingParams;
} }
hr = GetDWriteFactory()->CreateCustomRenderingParams( hr = Factory::GetDWriteFactory()->CreateCustomRenderingParams(
gamma, contrast, level, gamma, contrast, level,
dwriteGeometry, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC, dwriteGeometry, DWRITE_RENDERING_MODE_CLEARTYPE_GDI_CLASSIC,
getter_AddRefs(mRenderingParams[TEXT_RENDERING_GDI_CLASSIC])); getter_AddRefs(mRenderingParams[TEXT_RENDERING_GDI_CLASSIC]));
@ -1577,7 +1538,7 @@ gfxWindowsPlatform::InitializeD2D()
} }
// Using Direct2D depends on DWrite support. // Using Direct2D depends on DWrite support.
if (!mDWriteFactory && !InitDWriteSupport()) { if (!DWriteEnabled() && !InitDWriteSupport()) {
d2d1.SetFailed(FeatureStatus::Failed, "Failed to initialize DirectWrite support", d2d1.SetFailed(FeatureStatus::Failed, "Failed to initialize DirectWrite support",
NS_LITERAL_CSTRING("FEATURE_FAILURE_D2D_DWRITE")); NS_LITERAL_CSTRING("FEATURE_FAILURE_D2D_DWRITE"));
return; return;

View File

@ -192,8 +192,7 @@ public:
void SetupClearTypeParams(); void SetupClearTypeParams();
IDWriteFactory *GetDWriteFactory() { return mDWriteFactory; } inline bool DWriteEnabled() const { return !!mozilla::gfx::Factory::GetDWriteFactory(); }
inline bool DWriteEnabled() { return !!mDWriteFactory; }
inline DWRITE_MEASURING_MODE DWriteMeasuringMode() { return mMeasuringMode; } inline DWRITE_MEASURING_MODE DWriteMeasuringMode() { return mMeasuringMode; }
IDWriteRenderingParams *GetRenderingParams(TextRenderingMode aRenderMode) IDWriteRenderingParams *GetRenderingParams(TextRenderingMode aRenderMode)
@ -260,7 +259,6 @@ private:
void InitializeDirectDrawConfig(); void InitializeDirectDrawConfig();
void InitializeAdvancedLayersConfig(); void InitializeAdvancedLayersConfig();
RefPtr<IDWriteFactory> mDWriteFactory;
RefPtr<IDWriteRenderingParams> mRenderingParams[TEXT_RENDERING_COUNT]; RefPtr<IDWriteRenderingParams> mRenderingParams[TEXT_RENDERING_COUNT];
DWRITE_MEASURING_MODE mMeasuringMode; DWRITE_MEASURING_MODE mMeasuringMode;

View File

@ -83,20 +83,5 @@ PrintTranslator::CreateDrawTarget(ReferencePtr aRefPtr,
return drawTarget.forget(); return drawTarget.forget();
} }
FontType
PrintTranslator::GetDesiredFontType()
{
switch (mBaseDT->GetBackendType()) {
case BackendType::DIRECT2D:
return FontType::DWRITE;
case BackendType::CAIRO:
return FontType::CAIRO;
case BackendType::SKIA:
return FontType::SKIA;
default:
return FontType::CAIRO;
}
}
} // namespace layout } // namespace layout
} // namespace mozilla } // namespace mozilla

View File

@ -175,8 +175,6 @@ public:
mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final { return mBaseDT; } mozilla::gfx::DrawTarget* GetReferenceDrawTarget() final { return mBaseDT; }
mozilla::gfx::FontType GetDesiredFontType() final;
private: private:
RefPtr<nsDeviceContext> mDeviceContext; RefPtr<nsDeviceContext> mDeviceContext;
RefPtr<DrawTarget> mBaseDT; RefPtr<DrawTarget> mBaseDT;