Regularize selection of fontmgr.

Change-Id: Id7c51504450c1c7c9421eba3838bd6bc3440ca4f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295437
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2020-06-03 13:20:37 -04:00 committed by Skia Commit-Bot
parent de175abede
commit 75626e4b1a
6 changed files with 127 additions and 87 deletions

130
BUILD.gn
View File

@ -298,6 +298,11 @@ optional("android_utils") {
]
}
source_set("fontmgr_factory") {
configs += skia_library_configs
sources = [ skia_fontmgr_factory ]
}
optional("fontmgr_android") {
enabled = skia_enable_fontmgr_android
@ -305,57 +310,84 @@ optional("fontmgr_android") {
":typeface_freetype",
"//third_party/expat",
]
public = [ "include/ports/SkFontMgr_android.h" ]
sources = [
"src/ports/SkFontMgr_android.cpp",
"src/ports/SkFontMgr_android_factory.cpp",
"src/ports/SkFontMgr_android_parser.cpp",
"src/ports/SkFontMgr_android_parser.h",
]
}
optional("fontmgr_custom") {
enabled = skia_enable_fontmgr_custom
enabled =
skia_enable_fontmgr_custom_directory ||
skia_enable_fontmgr_custom_embedded || skia_enable_fontmgr_custom_empty
deps = [ ":typeface_freetype" ]
sources = [
"src/ports/SkFontMgr_custom.cpp",
"src/ports/SkFontMgr_custom.h",
"src/ports/SkFontMgr_custom_directory.cpp",
"src/ports/SkFontMgr_custom_directory_factory.cpp",
"src/ports/SkFontMgr_custom_embedded.cpp",
"src/ports/SkFontMgr_custom_empty.cpp",
public = [ "src/ports/SkFontMgr_custom.h" ]
sources = [ "src/ports/SkFontMgr_custom.cpp" ]
}
optional("fontmgr_custom_directory") {
enabled = skia_enable_fontmgr_custom_directory
deps = [
":fontmgr_custom",
":typeface_freetype",
]
public = [ "include/ports/SkFontMgr_directory.h" ]
sources = [ "src/ports/SkFontMgr_custom_directory.cpp" ]
}
optional("fontmgr_custom_embedded") {
enabled = skia_enable_fontmgr_custom_embedded
deps = [
":fontmgr_custom",
":typeface_freetype",
]
sources = [ "src/ports/SkFontMgr_custom_embedded.cpp" ]
}
optional("fontmgr_custom_empty") {
enabled = skia_enable_fontmgr_custom_empty
deps = [ ":typeface_freetype" ]
sources = [
"src/ports/SkFontMgr_custom.cpp",
"src/ports/SkFontMgr_custom_empty.cpp",
"src/ports/SkFontMgr_custom_empty_factory.cpp",
deps = [
":fontmgr_custom",
":typeface_freetype",
]
}
optional("fontmgr_empty") {
enabled = skia_enable_fontmgr_empty
sources = [ "src/ports/SkFontMgr_empty_factory.cpp" ]
public = [ "include/ports/SkFontMgr_empty.h" ]
sources = [ "src/ports/SkFontMgr_custom_empty.cpp" ]
}
optional("fontmgr_fontconfig") {
enabled = skia_use_freetype && skia_use_fontconfig
enabled = skia_enable_fontmgr_fontconfig
deps = [
":typeface_freetype",
"//third_party:fontconfig",
]
public = [ "include/ports/SkFontMgr_fontconfig.h" ]
sources = [ "src/ports/SkFontMgr_fontconfig.cpp" ]
}
optional("fontmgr_FontConfigInterface") {
enabled = skia_enable_fontmgr_FontConfigInterface
deps = [
":typeface_freetype",
"//third_party:fontconfig",
]
public = [
"include/ports/SkFontConfigInterface.h",
"include/ports/SkFontMgr_FontConfigInterface.h",
]
sources = [
"src/ports/SkFontConfigInterface.cpp",
"src/ports/SkFontConfigInterface_direct.cpp",
"src/ports/SkFontConfigInterface_direct_factory.cpp",
"src/ports/SkFontConfigTypeface.h",
"src/ports/SkFontMgr_FontConfigInterface.cpp",
"src/ports/SkFontMgr_fontconfig.cpp",
"src/ports/SkFontMgr_fontconfig_factory.cpp",
]
}
@ -369,19 +401,19 @@ optional("fontmgr_fuchsia") {
} else {
deps = [ "//sdk/fidl/fuchsia.fonts" ]
}
sources = [
"src/ports/SkFontMgr_fuchsia.cpp",
"src/ports/SkFontMgr_fuchsia.h",
]
public = [ "src/ports/SkFontMgr_fuchsia.h" ]
sources = [ "src/ports/SkFontMgr_fuchsia.cpp" ]
}
optional("fontmgr_mac") {
optional("fontmgr_mac_ct") {
enabled = skia_use_fonthost_mac
public = [ "include/ports/SkFontMgr_mac_ct.h" ]
public = [
"include/ports/SkFontMgr_mac_ct.h",
"include/ports/SkTypeface_mac.h",
]
sources = [
"src/ports/SkFontMgr_mac_ct.cpp",
"src/ports/SkFontMgr_mac_ct_factory.cpp",
"src/ports/SkScalerContext_mac_ct.cpp",
"src/ports/SkScalerContext_mac_ct.h",
"src/ports/SkTypeface_mac_ct.cpp",
@ -408,37 +440,13 @@ optional("fontmgr_mac") {
}
}
optional("fontmgr_wasm") {
enabled = target_cpu == "wasm"
deps = []
# custom_embedded has the source for both embedding a font in the binary
# (only used for the all-included build) and reading in a font from
# raw bytes passed over the wire (a typical way to load fonts).
if (!skia_enable_fontmgr_empty) {
deps += [ ":typeface_freetype" ]
sources = [ "src/ports/SkFontMgr_custom_embedded.cpp" ]
# If we haven't opted for no fonts (empty) or fonts, but not the
# built-in one (custom), then, we need to provide the mechanism for
# using the built-in font.
if (!skia_enable_fontmgr_custom) {
sources += [
"src/ports/SkFontMgr_custom.cpp",
"src/ports/SkFontMgr_custom.h",
"src/ports/SkFontMgr_custom_embedded_factory.cpp",
]
}
}
}
optional("fontmgr_win") {
enabled = skia_enable_fontmgr_win
public = [ "include/ports/SkTypeface_win.h" ]
sources = [
"src/fonts/SkFontMgr_indirect.cpp",
"src/ports/SkFontMgr_win_dw.cpp",
"src/ports/SkFontMgr_win_dw_factory.cpp",
"src/ports/SkScalerContext_win_dw.cpp",
"src/ports/SkTypeface_win_dw.cpp",
]
@ -447,6 +455,7 @@ optional("fontmgr_win") {
optional("fontmgr_win_gdi") {
enabled = skia_enable_fontmgr_win_gdi
public = [ "include/ports/SkTypeface_win.h" ]
sources = [ "src/ports/SkFontHost_win.cpp" ]
libs = [ "Gdi32.lib" ]
}
@ -920,14 +929,15 @@ component("skia") {
":avx",
":compile_processors",
":crc32",
":fontmgr_FontConfigInterface",
":fontmgr_android",
":fontmgr_custom",
":fontmgr_custom_directory",
":fontmgr_custom_embedded",
":fontmgr_custom_empty",
":fontmgr_empty",
":fontmgr_factory",
":fontmgr_fontconfig",
":fontmgr_fuchsia",
":fontmgr_mac",
":fontmgr_wasm",
":fontmgr_mac_ct",
":fontmgr_win",
":fontmgr_win_gdi",
":gif",
@ -1098,8 +1108,6 @@ if (target_cpu == "wasm") {
"tools/debugger/DrawCommand.cpp",
"tools/debugger/JsonWriteBuffer.cpp",
]
deps = [ ":fontmgr_wasm" ]
}
}
@ -1600,7 +1608,7 @@ if (skia_enable_tools) {
if (!skia_enable_fontmgr_android) {
sources -= [ "//tests/FontMgrAndroidParserTest.cpp" ]
}
if (!(skia_use_freetype && skia_use_fontconfig)) {
if (!skia_enable_fontmgr_fontconfig) {
sources -= [ "//tests/FontMgrFontConfigTest.cpp" ]
}
deps = [

View File

@ -130,6 +130,8 @@ echo "Compiling bitcode"
skia_use_wuffs=false \
skia_use_zlib=false \
skia_enable_fontmgr_empty=true \
skia_enable_fontmgr_custom_directory=false \
skia_enable_fontmgr_custom_embedded=false \
skia_enable_fontmgr_custom_empty=false \
skia_enable_sksl_interpreter=false \
\

View File

@ -288,30 +288,31 @@ cc_test {
# We'll run GN to get the main source lists and include directories for Skia.
def generate_args(target_os, enable_gpu):
d = {
'is_official_build': 'true',
'is_official_build': 'true',
# gn_to_bp_utils' GetArchSources will take care of architecture-specific
# files.
'target_cpu': '"none"',
'target_cpu': '"none"',
'skia_enable_android_utils': 'true',
'skia_enable_android_utils': 'true',
# Use the custom FontMgr, as the framework will handle fonts.
'skia_enable_fontmgr_custom': 'false',
'skia_enable_fontmgr_custom_empty': 'true',
'skia_enable_fontmgr_android': 'false',
'skia_enable_fontmgr_win': 'false',
'skia_enable_fontmgr_win_gdi': 'false',
'skia_use_fonthost_mac': 'false',
'skia_enable_fontmgr_custom_directory': 'false',
'skia_enable_fontmgr_custom_embedded': 'false',
'skia_enable_fontmgr_custom_empty': 'true',
'skia_enable_fontmgr_android': 'false',
'skia_enable_fontmgr_win': 'false',
'skia_enable_fontmgr_win_gdi': 'false',
'skia_use_fonthost_mac': 'false',
# enable features used in skia_nanobench
'skia_enable_sksl_interpreter': 'true',
'skia_tools_require_resources': 'true',
'skia_enable_sksl_interpreter': 'true',
'skia_tools_require_resources': 'true',
'skia_use_freetype': 'true',
'skia_use_fontconfig': 'false',
'skia_use_fixed_gamma_text': 'true',
'skia_include_multiframe_procs': 'false',
'skia_libgifcodec_path': '"third_party/libgifcodec"',
'skia_use_freetype': 'true',
'skia_use_fontconfig': 'false',
'skia_use_fixed_gamma_text': 'true',
'skia_include_multiframe_procs': 'false',
'skia_libgifcodec_path': '"third_party/libgifcodec"',
}
d['target_os'] = target_os
if target_os == '"android"':

View File

@ -94,9 +94,12 @@ declare_args() {
declare_args() {
skia_enable_fontmgr_android = skia_use_expat && skia_use_freetype
skia_enable_fontmgr_custom =
is_linux && skia_use_freetype && !skia_use_fontconfig
skia_enable_fontmgr_custom_empty = is_fuchsia && skia_use_freetype
skia_enable_fontmgr_custom_directory = skia_use_freetype && !is_fuchsia
skia_enable_fontmgr_custom_embedded = skia_use_freetype && !is_fuchsia
skia_enable_fontmgr_custom_empty = skia_use_freetype
skia_enable_fontmgr_fontconfig = skia_use_freetype && skia_use_fontconfig
skia_enable_fontmgr_FontConfigInterface =
skia_use_freetype && skia_use_fontconfig
skia_enable_nvpr = !skia_enable_flutter_defines
skia_enable_spirv_validation = is_skia_dev_build && is_debug && !skia_use_dawn
skia_use_dng_sdk =
@ -108,5 +111,30 @@ declare_args() {
skia_use_vma = skia_use_vulkan
}
declare_args() {
# skia_fontmgr_factory should define SkFontMgr::Factory()
if (skia_enable_fontmgr_empty) {
skia_fontmgr_factory = "src/ports/SkFontMgr_empty_factory.cpp"
} else if (is_android && skia_enable_fontmgr_android) {
skia_fontmgr_factory = "src/ports/SkFontMgr_android_factory.cpp"
} else if (is_win && skia_enable_fontmgr_win) {
skia_fontmgr_factory = "src/ports/SkFontMgr_win_dw_factory.cpp"
} else if (is_mac && skia_use_fonthost_mac) {
skia_fontmgr_factory = "src/ports/SkFontMgr_mac_ct_factory.cpp"
} else if (skia_enable_fontmgr_fontconfig) {
skia_fontmgr_factory = "src/ports/SkFontMgr_fontconfig_factory.cpp"
} else if (skia_enable_fontmgr_custom_directory) {
skia_fontmgr_factory = "src/ports/SkFontMgr_custom_directory_factory.cpp"
} else if (skia_enable_fontmgr_custom_embedded) {
skia_fontmgr_factory = "src/ports/SkFontMgr_custom_embedded_factory.cpp"
} else if (skia_enable_fontmgr_custom_empty) {
skia_fontmgr_factory = "src/ports/SkFontMgr_custom_empty_factory.cpp"
} else {
#"src/ports/SkFontMgr_FontConfigInterface_factory.cpp" #WontFix
#"src/ports/SkFontMgr_win_gdi_factory.cpp" # WontFix
skia_fontmgr_factory = "src/ports/SkFontMgr_empty_factory.cpp"
}
}
# Our tools require static linking (they use non-exported symbols), and the GPU backend.
skia_enable_tools = skia_enable_tools && !is_component_build && skia_enable_gpu

View File

@ -156,20 +156,18 @@ if [[ $@ == *no_canvas* ]]; then
HTML_CANVAS_API=""
fi
GN_FONT="skia_enable_fontmgr_empty=false skia_enable_fontmgr_custom_empty=false"
GN_FONT="skia_enable_fontmgr_custom_directory=false "
FONT_CFLAGS=""
BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp"
BUILTIN_FONT=""
FONT_JS="--pre-js $BASE_DIR/font.js"
if [[ $@ == *no_font* ]]; then
echo "Omitting the built-in font(s), font manager and all code dealing with fonts"
BUILTIN_FONT=""
FONT_CFLAGS="-DSK_NO_FONTS"
FONT_JS=""
GN_FONT="skia_enable_fontmgr_empty=true skia_enable_fontmgr_custom_empty=false"
GN_FONT+="skia_enable_fontmgr_custom_embedded=false skia_enable_fontmgr_custom_empty=false"
elif [[ $@ == *no_embedded_font* ]]; then
echo "Omitting the built-in font(s)"
BUILTIN_FONT=""
GN_FONT="skia_enable_fontmgr_empty=false skia_enable_fontmgr_custom_empty=true"
GN_FONT+="skia_enable_fontmgr_custom_embedded=false skia_enable_fontmgr_custom_empty=true"
else
# Generate the font's binary file (which is covered by .gitignore)
python tools/embed_resources.py \
@ -177,6 +175,8 @@ else
--input $BASE_DIR/fonts/NotoMono-Regular.ttf \
--output $BASE_DIR/fonts/NotoMono-Regular.ttf.cpp \
--align 4
BUILTIN_FONT="$BASE_DIR/fonts/NotoMono-Regular.ttf.cpp"
GN_FONT+="skia_enable_fontmgr_custom_embedded=true skia_enable_fontmgr_custom_empty=false"
fi
if [[ $@ == *no_alias_font* ]]; then

View File

@ -12,7 +12,8 @@ less machine- and platform- dependent:
skia_use_system_freetype2=false
skia_use_wuffs=true
skia_enable_skottie=true
skia_enable_fontmgr_custom=false
skia_enable_fontmgr_custom_directory=false
skia_enable_fontmgr_custom_embedded=false
skia_enable_fontmgr_custom_empty=true
All that is needed to reproduce a fuzz downloaded from ClusterFuzz, oss-fuzz or