Bug 1421275 - Pass FontInstanceFlags to WebRender. r?jrmuizel
This patch was originally developed on
bug 1418564.
MozReview-Commit-ID: 53oydIqjhvF
--- a/gfx/2d/ScaledFontDWrite.cpp
+++ b/gfx/2d/ScaledFontDWrite.cpp
@@ -386,31 +386,31 @@ ScaledFontDWrite::GetFontInstanceData(Fo
return true;
}
bool
ScaledFontDWrite::GetWRFontInstanceOptions(Maybe<wr::FontInstanceOptions>* aOutOptions,
Maybe<wr::FontInstancePlatformOptions>* aOutPlatformOptions,
std::vector<FontVariation>* aOutVariations)
{
- AntialiasMode aaMode = GetDefaultAAMode();
- if (aaMode != AntialiasMode::SUBPIXEL) {
- wr::FontInstanceOptions options;
- options.render_mode =
- aaMode == AntialiasMode::NONE ? wr::FontRenderMode::Mono : wr::FontRenderMode::Alpha;
- options.subpx_dir = wr::SubpixelDirection::Horizontal;
- options.synthetic_italics = false;
- options.bg_color = wr::ToColorU(Color());
- *aOutOptions = Some(options);
+ wr::FontInstanceOptions options;
+ options.render_mode = wr::ToFontRenderMode(GetDefaultAAMode());
+ options.subpx_dir = wr::SubpixelDirection::Horizontal;
+ options.flags = 0;
+ if (mFontFace->GetSimulations() & DWRITE_FONT_SIMULATIONS_BOLD) {
+ options.flags |= wr::FontInstanceFlags::SYNTHETIC_BOLD;
}
-
- wr::FontInstancePlatformOptions platformOptions;
- platformOptions.use_embedded_bitmap = UseEmbeddedBitmaps();
- platformOptions.force_gdi_rendering = ForceGDIMode();
- *aOutPlatformOptions = Some(platformOptions);
+ if (UseEmbeddedBitmaps()) {
+ options.flags |= wr::FontInstanceFlags::EMBEDDED_BITMAPS;
+ }
+ if (ForceGDIMode()) {
+ options.flags |= wr::FontInstanceFlags::FORCE_GDI;
+ }
+ options.bg_color = wr::ToColorU(Color());
+ *aOutOptions = Some(options);
return true;
}
already_AddRefed<ScaledFont>
UnscaledFontDWrite::CreateScaledFont(Float aGlyphSize,
const uint8_t* aInstanceData,
uint32_t aInstanceDataLength,
const FontVariation* aVariations,
--- a/gfx/2d/ScaledFontFontconfig.cpp
+++ b/gfx/2d/ScaledFontFontconfig.cpp
@@ -11,27 +11,16 @@
#ifdef USE_SKIA
#include "skia/include/ports/SkTypeface_cairo.h"
#endif
#include <fontconfig/fcfreetype.h>
namespace mozilla {
-namespace wr {
- enum {
- FONT_FORCE_AUTOHINT = 1 << 0,
- FONT_NO_AUTOHINT = 1 << 1,
- FONT_EMBEDDED_BITMAP = 1 << 2,
- FONT_EMBOLDEN = 1 << 3,
- FONT_VERTICAL_LAYOUT = 1 << 4,
- FONT_SUBPIXEL_BGR = 1 << 5
- };
-}
-
namespace gfx {
// On Linux and Android our "platform" font is a cairo_scaled_font_t and we use
// an SkFontHost implementation that allows Skia to render using this.
// This is mainly because FT_Face is not good for sharing between libraries, which
// is a requirement when we consider runtime switchable backends and so on
ScaledFontFontconfig::ScaledFontFontconfig(cairo_scaled_font_t* aScaledFont,
FcPattern* aPattern,
@@ -247,35 +236,34 @@ ScaledFontFontconfig::GetFontInstanceDat
bool
ScaledFontFontconfig::GetWRFontInstanceOptions(Maybe<wr::FontInstanceOptions>* aOutOptions,
Maybe<wr::FontInstancePlatformOptions>* aOutPlatformOptions,
std::vector<FontVariation>* aOutVariations)
{
wr::FontInstanceOptions options;
options.render_mode = wr::FontRenderMode::Alpha;
options.subpx_dir = wr::SubpixelDirection::Horizontal;
- options.synthetic_italics = false;
+ options.flags = 0;
options.bg_color = wr::ToColorU(Color());
wr::FontInstancePlatformOptions platformOptions;
- platformOptions.flags = 0;
platformOptions.lcd_filter = wr::FontLCDFilter::Legacy;
platformOptions.hinting = wr::FontHinting::Normal;
FcBool autohint;
if (FcPatternGetBool(mPattern, FC_AUTOHINT, 0, &autohint) == FcResultMatch && autohint) {
- platformOptions.flags |= wr::FONT_FORCE_AUTOHINT;
+ options.flags |= wr::FontInstanceFlags::FORCE_AUTOHINT;
}
FcBool embolden;
if (FcPatternGetBool(mPattern, FC_EMBOLDEN, 0, &embolden) == FcResultMatch && embolden) {
- platformOptions.flags |= wr::FONT_EMBOLDEN;
+ options.flags |= wr::FontInstanceFlags::SYNTHETIC_BOLD;
}
FcBool vertical;
if (FcPatternGetBool(mPattern, FC_VERTICAL_LAYOUT, 0, &vertical) == FcResultMatch && vertical) {
- platformOptions.flags |= wr::FONT_VERTICAL_LAYOUT;
+ options.flags |= wr::FontInstanceFlags::VERTICAL_LAYOUT;
}
FcBool antialias;
if (FcPatternGetBool(mPattern, FC_ANTIALIAS, 0, &antialias) != FcResultMatch || antialias) {
int rgba;
if (FcPatternGetInteger(mPattern, FC_RGBA, 0, &rgba) == FcResultMatch) {
switch (rgba) {
case FC_RGBA_RGB:
@@ -283,17 +271,17 @@ ScaledFontFontconfig::GetWRFontInstanceO
case FC_RGBA_VRGB:
case FC_RGBA_VBGR:
options.render_mode = wr::FontRenderMode::Subpixel;
if (rgba == FC_RGBA_VRGB || rgba == FC_RGBA_VBGR) {
options.subpx_dir = wr::SubpixelDirection::Vertical;
}
platformOptions.hinting = wr::FontHinting::LCD;
if (rgba == FC_RGBA_BGR || rgba == FC_RGBA_VBGR) {
- platformOptions.flags |= wr::FONT_SUBPIXEL_BGR;
+ options.flags |= wr::FontInstanceFlags::SUBPIXEL_BGR;
}
break;
case FC_RGBA_NONE:
case FC_RGBA_UNKNOWN:
default:
break;
}
}
@@ -318,23 +306,23 @@ ScaledFontFontconfig::GetWRFontInstanceO
}
}
// Match cairo-ft's handling of embeddedbitmap:
// If AA is explicitly disabled, leave bitmaps enabled.
// Otherwise, disable embedded bitmaps unless explicitly enabled.
FcBool bitmap;
if (FcPatternGetBool(mPattern, FC_EMBEDDED_BITMAP, 0, &bitmap) == FcResultMatch && bitmap) {
- platformOptions.flags |= wr::FONT_EMBEDDED_BITMAP;
+ options.flags |= wr::FontInstanceFlags::EMBEDDED_BITMAPS;
}
} else {
options.render_mode = wr::FontRenderMode::Mono;
options.subpx_dir = wr::SubpixelDirection::None;
platformOptions.hinting = wr::FontHinting::Mono;
- platformOptions.flags |= wr::FONT_EMBEDDED_BITMAP;
+ options.flags |= wr::FontInstanceFlags::EMBEDDED_BITMAPS;
}
FcBool hinting;
int hintstyle;
if (FcPatternGetBool(mPattern, FC_HINTING, 0, &hinting) != FcResultMatch || hinting) {
if (FcPatternGetInteger(mPattern, FC_HINT_STYLE, 0, &hintstyle) != FcResultMatch) {
hintstyle = FC_HINT_FULL;
}
--- a/gfx/2d/ScaledFontMac.cpp
+++ b/gfx/2d/ScaledFontMac.cpp
@@ -385,43 +385,42 @@ GetVariationsForCTFont(CTFontRef aCTFont
CFDictionaryApplyFunction(dict, CollectVariationsFromDictionary, aOutVariations);
}
return true;
}
bool
ScaledFontMac::GetFontInstanceData(FontInstanceDataOutput aCb, void* aBaton)
{
- // Collect any variation settings that were incorporated into the CTFont.
- std::vector<FontVariation> variations;
- if (!GetVariationsForCTFont(mCTFont, &variations)) {
- return false;
- }
- aCb(nullptr, 0, variations.data(), variations.size(), aBaton);
- return true;
+ // Collect any variation settings that were incorporated into the CTFont.
+ std::vector<FontVariation> variations;
+ if (!GetVariationsForCTFont(mCTFont, &variations)) {
+ return false;
+ }
+ aCb(nullptr, 0, variations.data(), variations.size(), aBaton);
+ return true;
}
bool
ScaledFontMac::GetWRFontInstanceOptions(Maybe<wr::FontInstanceOptions>* aOutOptions,
Maybe<wr::FontInstancePlatformOptions>* aOutPlatformOptions,
std::vector<FontVariation>* aOutVariations)
{
- GetVariationsForCTFont(mCTFont, aOutVariations);
+ GetVariationsForCTFont(mCTFont, aOutVariations);
- wr::FontInstanceOptions options;
- options.render_mode = wr::FontRenderMode::Subpixel;
- options.subpx_dir = wr::SubpixelDirection::Horizontal;
- options.synthetic_italics = false;
- options.bg_color = wr::ToColorU(mFontSmoothingBackgroundColor);
- *aOutOptions = Some(options);
-
- wr::FontInstancePlatformOptions platformOptions;
- platformOptions.font_smoothing = mUseFontSmoothing;
- *aOutPlatformOptions = Some(platformOptions);
- return true;
+ wr::FontInstanceOptions options;
+ options.render_mode = wr::FontRenderMode::Subpixel;
+ options.subpx_dir = wr::SubpixelDirection::Horizontal;
+ options.flags = 0;
+ if (mUseFontSmoothing) {
+ options.flags |= wr::FontInstanceFlags::FONT_SMOOTHING;
+ }
+ options.bg_color = wr::ToColorU(mFontSmoothingBackgroundColor);
+ *aOutOptions = Some(options);
+ return true;
}
static CFDictionaryRef
CreateVariationDictionaryOrNull(CGFontRef aCGFont, uint32_t aVariationCount,
const FontVariation* aVariations)
{
// Avoid calling potentially buggy variation APIs on pre-Sierra macOS
// versions (see bug 1331683)
--- a/gfx/webrender_bindings/webrender_ffi.h
+++ b/gfx/webrender_bindings/webrender_ffi.h
@@ -24,16 +24,56 @@ bool gfx_use_wrench();
const char* gfx_wr_resource_path_override();
void gfx_critical_note(const char* msg);
void gfx_critical_error(const char* msg);
void gecko_printf_stderr_output(const char* msg);
void* get_proc_address_from_glcontext(void* glcontext_ptr, const char* procname);
void gecko_profiler_register_thread(const char* threadname);
void gecko_profiler_unregister_thread();
+// Prelude of types necessary before including webrender_ffi_generated.h
+namespace mozilla {
+namespace wr {
+
+struct FontInstanceFlags {
+ uint32_t bits;
+
+ bool operator==(const FontInstanceFlags& aOther) const {
+ return bits == aOther.bits;
+ }
+
+ FontInstanceFlags& operator=(uint32_t aBits) {
+ bits = aBits;
+ return *this;
+ }
+
+ FontInstanceFlags& operator|=(uint32_t aBits) {
+ bits |= aBits;
+ return *this;
+ }
+
+ enum : uint32_t {
+ SYNTHETIC_ITALICS = 1 << 0,
+ SYNTHETIC_BOLD = 1 << 1,
+ EMBEDDED_BITMAPS = 1 << 2,
+ SUBPIXEL_BGR = 1 << 3,
+
+ FORCE_GDI = 1 << 16,
+
+ FONT_SMOOTHING = 1 << 16,
+
+ FORCE_AUTOHINT = 1 << 16,
+ NO_AUTOHINT = 1 << 17,
+ VERTICAL_LAYOUT = 1 << 18
+ };
+};
+
+} // namespace wr
+} // namespace mozilla
+
} // extern "C"
// Some useful defines to stub out webrender binding functions for when we
// build gecko without webrender. We try to tell the compiler these functions
// are unreachable in that case, but VC++ emits a warning if it finds any
// unreachable functions invoked from destructors. That warning gets turned into
// an error and causes the build to fail. So for wr_* functions called by
// destructors in C++ classes, use WR_DESTRUCTOR_SAFE_FUNC instead, which omits