Commit 023f5763 authored by Dominik Röttsches's avatar Dominik Röttsches Committed by Commit Bot

Switch Mac OS HarfBuzz hb_face creation to table copying

Removing the CTFont based construction when rolling to HarfBuzz' native
AAT lead us to falling back to attempting the mmap'ed access to the font
SkStreamAsset. However, the implementation for onOpenStream in
SkTypeface_Mac is highly inefficient and synthesizes a font from copying
all tables. Disable this type of instantiation on Mac and use the table
copy method instead.

This should address memory regression for the HarfBuzz AAT roll [1].

[1] https://chromium.googlesource.com/chromium/src/+/c67f53b0b70f33c47159d37f7e59bb44399b0d09

Bug: 908552
Change-Id: Ibf19ea6308f34fd4927e2b7fd59cdff20f3aad6d
Tbr: eae@chromium.org, behdad@chromium.org
Reviewed-on: https://chromium-review.googlesource.com/c/1355129Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarBehdad Esfahbod <behdad@chromium.org>
Reviewed-by: default avatarBen Wagner <bungeman@chromium.org>
Commit-Queue: Dominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612233}
parent 058930e6
......@@ -32,6 +32,7 @@
#include <memory>
#include "build/build_config.h"
#include "third_party/blink/renderer/platform/fonts/font_cache.h"
#include "third_party/blink/renderer/platform/fonts/font_global_context.h"
#include "third_party/blink/renderer/platform/fonts/font_platform_data.h"
......@@ -334,11 +335,13 @@ static hb_blob_t* HarfBuzzSkiaGetTable(hb_face_t* face,
WTF::Partitions::FastFree);
}
#if !defined(OS_MACOSX)
static void DeleteTypefaceStream(void* stream_asset_ptr) {
SkStreamAsset* stream_asset =
reinterpret_cast<SkStreamAsset*>(stream_asset_ptr);
delete stream_asset;
}
#endif
hb_face_t* HarfBuzzFace::CreateFace() {
hb_face_t* face = nullptr;
......@@ -347,6 +350,11 @@ hb_face_t* HarfBuzzFace::CreateFace() {
("Blink.Fonts.HarfBuzzFaceZeroCopyAccess"));
SkTypeface* typeface = platform_data_->Typeface();
CHECK(typeface);
// The attempt of doing zero copy-mmaped memory access to the font blobs does
// not work efficiently on Mac, since what is returned from
// typeface->openStream is a synthesized font assembled from copying all font
// tables on Mac. See the implementation of SkTypeface_Mac::onOpenStream.
#if !defined(OS_MACOSX)
int ttc_index = 0;
SkStreamAsset* typeface_stream = typeface->openStream(&ttc_index);
if (typeface_stream && typeface_stream->getMemoryBase()) {
......@@ -358,6 +366,7 @@ hb_face_t* HarfBuzzFace::CreateFace() {
hb_blob_destroy);
face = hb_face_create(face_blob.get(), ttc_index);
}
#endif
// Fallback to table copies if there is no in-memory access.
if (!face) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment