Skip to content

Commit

Permalink
Use efficient ftsystem.c when possible.
Browse files Browse the repository at this point in the history
Some builds of Chromium include FontConfig as another user of FreeType.
Some of these builds will use FontConfig to scan a number of font files
to build an FcConfig. Using an optimized version of ftsystem.c can speed
this process significantly.

Change-Id: I6b0efc4969a1d23a4683662c246eafd9ab7760de
Reviewed-on: https://chromium-review.googlesource.com/585389
Commit-Queue: Ben Wagner <bungeman@chromium.org>
Reviewed-by: Dominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/master@{#490002}
  • Loading branch information
bungeman authored and Commit Bot committed Jul 27, 2017
1 parent b5168e0 commit 6407827
Show file tree
Hide file tree
Showing 4 changed files with 533 additions and 7 deletions.
35 changes: 30 additions & 5 deletions third_party/freetype/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ config("freetype-warnings") {
# FreeType itself. Then we build FreeType depending on harfbuzz-ng-ft and
# harfbuzz-ng.
static_library("bootstrap_freetype_for_harfbuzz") {
visibility = [ "//third_party/harfbuzz-ng:harfbuzz-ng-ft", ":freetype" ]
visibility = [
"//third_party/harfbuzz-ng:harfbuzz-ng-ft",
":freetype",
]

defines = []

Expand All @@ -41,9 +44,32 @@ static_library("bootstrap_freetype_for_harfbuzz") {
"include/freetype-custom-config/ftoption.h",
"src/src/base/ftbase.c",
"src/src/base/ftbitmap.c",
"src/src/base/ftsystem.c",
]

include_dirs = []

# ftsystem.c provides implementations of FT_Memory and FT_Stream_Open.
# While Chromium itself avoids using this code, any build of Chromium which
# depends on //third_party/fontconfig:fontconfig with use_bundled_fontconfig
# will make heavy use of these implementations, so use the best available.
if (is_posix) {
sources += [ "src/builds/unix/ftsystem.c" ]

# builds/unix/ftsystem.c directly includes <ftconfig.h> instead of using
# FT_CONFIG_CONFIG_H. The includes/freetype/config directory should not be
# on the include path to avoid accidentally using the ftoption or ftmodule
# from there.
include_dirs += [ "include/freetype-custom-config" ]

# builds/unix/ftsystem.c requires the following defines to be set.
defines += [
"HAVE_UNISTD_H",
"HAVE_FCNTL_H",
]
} else {
sources += [ "src/src/base/ftsystem.c" ]
}

if (is_mac && !is_component_build) {
defines += [ "MAC_RESTRICT_VISIBILITY" ]
}
Expand Down Expand Up @@ -144,6 +170,7 @@ component("freetype") {
# GN currently does not escape '<' and '>' when generating xml based Visual
# Studio project files. As a result, use quotes instead of pointy brackets
# in these defines.
"FT_CONFIG_CONFIG_H=\"freetype-custom-config/ftconfig.h\"",
"FT_CONFIG_MODULES_H=\"freetype-custom-config/ftmodule.h\"",
"FT_CONFIG_OPTIONS_H=\"freetype-custom-config/ftoption.h\"",
]
Expand All @@ -165,9 +192,7 @@ component("freetype") {
]

if (!use_system_freetype) {
deps += [
":bootstrap_freetype_for_harfbuzz"
]
deps += [ ":bootstrap_freetype_for_harfbuzz" ]
}

if (!use_system_harfbuzz) {
Expand Down
8 changes: 6 additions & 2 deletions third_party/freetype/README.chromium
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ How to update:
2. Update BUILD.gn to reflect any changes.
3. Merge the new src/include/freetype/config/ftoption.h into
include/freetype-custom-config/ftoption.h .
4. Update this file.
5. Commit build changes while rolling Chromium's freetype DEPS to the
4. Merge the new src/include/freetype/config/ftconfig.h into
include/freetype-custom-config/ftconfig.h .
5. Update this file.
6. Commit build changes while rolling Chromium's freetype DEPS to the
new commit.

Most of the updating can be automated will roll-freetype.sh.
Loading

0 comments on commit 6407827

Please sign in to comment.