mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 842894 - Support DirectWrite using the Skia backend. r=bas
This commit is contained in:
parent
a1d19ba0c4
commit
1191c6a5de
@ -42,6 +42,9 @@ struct ID3D11Texture2D;
|
||||
struct ID3D11Device;
|
||||
struct ID2D1Device;
|
||||
struct IDWriteRenderingParams;
|
||||
struct IDWriteFont;
|
||||
struct IDWriteFontFamily;
|
||||
struct IDWriteFontFace;
|
||||
|
||||
class GrContext;
|
||||
|
||||
@ -1371,6 +1374,12 @@ public:
|
||||
static uint64_t GetD2DVRAMUsageSourceSurface();
|
||||
static void D2DCleanup();
|
||||
|
||||
static already_AddRefed<ScaledFont>
|
||||
CreateScaledFontForDWriteFont(IDWriteFont* aFont,
|
||||
IDWriteFontFamily* aFontFamily,
|
||||
IDWriteFontFace* aFontFace,
|
||||
Float aSize);
|
||||
|
||||
private:
|
||||
static ID2D1Device *mD2D1Device;
|
||||
static ID3D10Device1 *mD3D10Device;
|
||||
|
@ -583,7 +583,8 @@ DrawTargetSkia::FillGlyphs(ScaledFont *aFont,
|
||||
{
|
||||
if (aFont->GetType() != FontType::MAC &&
|
||||
aFont->GetType() != FontType::SKIA &&
|
||||
aFont->GetType() != FontType::GDI) {
|
||||
aFont->GetType() != FontType::GDI &&
|
||||
aFont->GetType() != FontType::DWRITE) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -786,6 +786,15 @@ Factory::D2DCleanup()
|
||||
DrawTargetD2D::CleanupD2D();
|
||||
}
|
||||
|
||||
already_AddRefed<ScaledFont>
|
||||
Factory::CreateScaledFontForDWriteFont(IDWriteFont* aFont,
|
||||
IDWriteFontFamily* aFontFamily,
|
||||
IDWriteFontFace* aFontFace,
|
||||
float aSize)
|
||||
{
|
||||
return MakeAndAddRef<ScaledFontDWrite>(aFont, aFontFamily, aFontFace, aSize);
|
||||
}
|
||||
|
||||
#endif // XP_WIN
|
||||
|
||||
#ifdef USE_SKIA_GPU
|
||||
|
@ -3,9 +3,17 @@
|
||||
* 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/. */
|
||||
|
||||
#include "DrawTargetD2D.h"
|
||||
#include "ScaledFontDWrite.h"
|
||||
#include "PathD2D.h"
|
||||
|
||||
#ifdef USE_SKIA
|
||||
#include "PathSkia.h"
|
||||
#include "skia/include/core/SkPaint.h"
|
||||
#include "skia/include/core/SkPath.h"
|
||||
#include "skia/include/ports/SkTypeface_win.h"
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
#ifdef USE_CAIRO_SCALED_FONT
|
||||
@ -105,6 +113,20 @@ ScaledFontDWrite::GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget
|
||||
return pathBuilder->Finish();
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_SKIA
|
||||
SkTypeface*
|
||||
ScaledFontDWrite::GetSkTypeface()
|
||||
{
|
||||
MOZ_ASSERT(mFont);
|
||||
if (!mTypeface) {
|
||||
IDWriteFactory *factory = DrawTargetD2D::GetDWriteFactory();
|
||||
mTypeface = SkCreateTypefaceFromDWriteFont(factory, mFontFace, mFont, mFontFamily);
|
||||
}
|
||||
return mTypeface;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
ScaledFontDWrite::CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, BackendType aBackendType, const Matrix *aTransformHint)
|
||||
{
|
||||
|
@ -20,9 +20,19 @@ public:
|
||||
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFontDwrite)
|
||||
ScaledFontDWrite(IDWriteFontFace *aFont, Float aSize)
|
||||
: ScaledFontBase(aSize)
|
||||
, mFont(nullptr)
|
||||
, mFontFamily(nullptr)
|
||||
, mFontFace(aFont)
|
||||
{}
|
||||
|
||||
ScaledFontDWrite(IDWriteFont* aFont, IDWriteFontFamily* aFontFamily,
|
||||
IDWriteFontFace *aFontFace, Float aSize)
|
||||
: ScaledFontBase(aSize)
|
||||
, mFont(aFont)
|
||||
, mFontFamily(aFontFamily)
|
||||
, mFontFace(aFontFace)
|
||||
{}
|
||||
|
||||
virtual FontType GetType() const { return FontType::DWRITE; }
|
||||
|
||||
virtual already_AddRefed<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget);
|
||||
@ -35,13 +45,11 @@ public:
|
||||
virtual AntialiasMode GetDefaultAAMode();
|
||||
|
||||
#ifdef USE_SKIA
|
||||
virtual SkTypeface* GetSkTypeface()
|
||||
{
|
||||
MOZ_ASSERT(false, "Skia and DirectWrite do not mix");
|
||||
return nullptr;
|
||||
}
|
||||
virtual SkTypeface* GetSkTypeface();
|
||||
#endif
|
||||
|
||||
RefPtr<IDWriteFont> mFont;
|
||||
RefPtr<IDWriteFontFamily> mFontFamily;
|
||||
RefPtr<IDWriteFontFace> mFontFace;
|
||||
|
||||
protected:
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define SkTypeface_win_DEFINED
|
||||
|
||||
#include "SkTypeface.h"
|
||||
#include <dwrite.h>
|
||||
|
||||
#ifdef SK_BUILD_FOR_WIN
|
||||
|
||||
@ -41,6 +42,16 @@ class SkFontMgr;
|
||||
class SkRemotableFontMgr;
|
||||
struct IDWriteFactory;
|
||||
|
||||
/**
|
||||
* Like the other Typeface create methods, this returns a new reference to the
|
||||
* corresponding typeface for the specified dwrite font. The caller is responsible
|
||||
* for calling unref() when it is finished.
|
||||
*/
|
||||
SK_API SkTypeface* SkCreateTypefaceFromDWriteFont(IDWriteFactory* aFactory,
|
||||
IDWriteFontFace* aFontFace,
|
||||
IDWriteFont* aFont,
|
||||
IDWriteFontFamily* aFontFamily);
|
||||
|
||||
SK_API SkFontMgr* SkFontMgr_New_GDI();
|
||||
SK_API SkFontMgr* SkFontMgr_New_DirectWrite(IDWriteFactory* factory = NULL);
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "SkString.h"
|
||||
#include "SkTemplates.h"
|
||||
#include "SkTypeface_win.h"
|
||||
#include "SkTypeface_win_dw.h"
|
||||
#include "SkTypefaceCache.h"
|
||||
#include "SkUtils.h"
|
||||
|
||||
@ -330,6 +331,18 @@ SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT& origLF) {
|
||||
return face;
|
||||
}
|
||||
|
||||
/***
|
||||
* This guy is public.
|
||||
*/
|
||||
|
||||
SkTypeface* SkCreateTypefaceFromDWriteFont(IDWriteFactory* aFactory,
|
||||
IDWriteFontFace* aFontFace,
|
||||
IDWriteFont* aFont,
|
||||
IDWriteFontFamily* aFontFamily)
|
||||
{
|
||||
return DWriteFontTypeface::Create(aFactory, aFontFace, aFont, aFontFamily);
|
||||
}
|
||||
|
||||
/**
|
||||
* The created SkTypeface takes ownership of fontMemResource.
|
||||
*/
|
||||
|
@ -342,6 +342,24 @@ gfxDWriteFontFamily::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
|
||||
AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
|
||||
}
|
||||
|
||||
already_AddRefed<IDWriteFont>
|
||||
gfxDWriteFontFamily::GetDefaultFont()
|
||||
{
|
||||
RefPtr<IDWriteFont> font;
|
||||
for (UINT32 i = 0; i < mDWFamily->GetFontCount(); i++) {
|
||||
HRESULT hr = mDWFamily->GetFont(i, getter_AddRefs(font));
|
||||
if (FAILED(hr)) {
|
||||
NS_WARNING("Failed to get default font from existing family");
|
||||
continue;
|
||||
}
|
||||
|
||||
return font.forget();
|
||||
}
|
||||
|
||||
NS_WARNING("No available DWrite fonts. Returning null");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// gfxDWriteFontEntry
|
||||
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
||||
FontListSizes* aSizes) const;
|
||||
|
||||
already_AddRefed<IDWriteFont> GetDefaultFont();
|
||||
protected:
|
||||
/** This font family's directwrite fontfamily object */
|
||||
RefPtr<IDWriteFontFamily> mDWFamily;
|
||||
@ -165,6 +166,10 @@ public:
|
||||
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
||||
FontListSizes* aSizes) const;
|
||||
|
||||
IDWriteFont* GetFont() {
|
||||
return mFont;
|
||||
}
|
||||
|
||||
protected:
|
||||
friend class gfxDWriteFont;
|
||||
friend class gfxDWriteFontList;
|
||||
|
@ -82,7 +82,7 @@ gfxDWriteFont::gfxDWriteFont(gfxFontEntry *aFontEntry,
|
||||
, mAllowManualShowGlyphs(true)
|
||||
{
|
||||
gfxDWriteFontEntry *fe =
|
||||
static_cast<gfxDWriteFontEntry*>(aFontEntry);
|
||||
static_cast<gfxDWriteFontEntry*>(aFontEntry);
|
||||
nsresult rv;
|
||||
DWRITE_FONT_SIMULATIONS sims = DWRITE_FONT_SIMULATIONS_NONE;
|
||||
if ((GetStyle()->style != NS_FONT_STYLE_NORMAL) &&
|
||||
@ -103,6 +103,21 @@ gfxDWriteFont::gfxDWriteFont(gfxFontEntry *aFontEntry,
|
||||
return;
|
||||
}
|
||||
|
||||
mFont = fe->GetFont();
|
||||
if (!mFont) {
|
||||
gfxPlatformFontList* fontList = gfxPlatformFontList::PlatformFontList();
|
||||
gfxDWriteFontFamily* defaultFontFamily =
|
||||
static_cast<gfxDWriteFontFamily*>(fontList->GetDefaultFont(aFontStyle));
|
||||
|
||||
mFont = defaultFontFamily->GetDefaultFont();
|
||||
NS_WARNING("Using default font");
|
||||
}
|
||||
|
||||
HRESULT hr = mFont->GetFontFamily(getter_AddRefs(mFontFamily));
|
||||
if (FAILED(hr)) {
|
||||
MOZ_ASSERT(false);
|
||||
}
|
||||
|
||||
ComputeMetrics(anAAOption);
|
||||
}
|
||||
|
||||
@ -684,6 +699,10 @@ gfxDWriteFont::GetScaledFont(mozilla::gfx::DrawTarget *aTarget)
|
||||
mAzureScaledFont = Factory::CreateScaledFontWithCairo(nativeFont,
|
||||
GetAdjustedSize(),
|
||||
GetCairoScaledFont());
|
||||
} else if (aTarget->GetBackendType() == BackendType::SKIA) {
|
||||
mAzureScaledFont =
|
||||
Factory::CreateScaledFontForDWriteFont(mFont, mFontFamily,
|
||||
mFontFace, GetAdjustedSize());
|
||||
} else {
|
||||
mAzureScaledFont = Factory::CreateScaledFontForNativeFont(nativeFont,
|
||||
GetAdjustedSize());
|
||||
|
@ -91,6 +91,8 @@ protected:
|
||||
bool GetForceGDIClassic();
|
||||
|
||||
RefPtr<IDWriteFontFace> mFontFace;
|
||||
RefPtr<IDWriteFont> mFont;
|
||||
RefPtr<IDWriteFontFamily> mFontFamily;
|
||||
cairo_font_face_t *mCairoFontFace;
|
||||
|
||||
Metrics *mMetrics;
|
||||
|
@ -700,9 +700,7 @@ gfxWindowsPlatform::CreatePlatformFontList()
|
||||
#ifdef CAIRO_HAS_DWRITE_FONT
|
||||
// bug 630201 - older pre-RTM versions of Direct2D/DirectWrite cause odd
|
||||
// crashers so blacklist them altogether
|
||||
if (IsNotWin7PreRTM() && GetDWriteFactory() &&
|
||||
// Skia doesn't support DirectWrite fonts yet.
|
||||
(gfxPlatform::GetDefaultContentBackend() != BackendType::SKIA)) {
|
||||
if (IsNotWin7PreRTM() && GetDWriteFactory()) {
|
||||
pfl = new gfxDWriteFontList();
|
||||
if (NS_SUCCEEDED(pfl->InitFontList())) {
|
||||
return pfl;
|
||||
|
Loading…
Reference in New Issue
Block a user