0

Remove final use of legacy SkFontMgr methods

This fixed one case of overloading a deprecated method (font_loader)
and one case of implicitly depending on the default font manager
by depending on the default SkTypeface deserialization logic.
Other places, e.g. printing [1], already explicitly passed in
the system font manager.

[1] https://source.chromium.org/chromium/chromium/src/+/main:printing/common/metafile_utils.cc;l=302-333;drc=24da48fcb484a544fe2be720172ec56af19532c2

Bug: b:305780908
Change-Id: I2778be72deb59d14abceb119f2ff7e0c5b3b3b90
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5105288
Reviewed-by: Calder Kitagawa <ckitagawa@chromium.org>
Auto-Submit: Kevin Lubick <kjlubick@chromium.org>
Commit-Queue: Kevin Lubick <kjlubick@chromium.org>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1237611}
This commit is contained in:
Kevin Lubick
2023-12-14 18:11:11 +00:00
committed by Chromium LUCI CQ
parent 9eea5d6a4c
commit fa624b96d0
4 changed files with 28 additions and 4 deletions
components
paint_preview
services
skia

@ -17,11 +17,13 @@
#include "third_party/skia/include/codec/SkWebpDecoder.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkData.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkImageInfo.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkString.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/skia/include/encode/SkPngEncoder.h"
#include "third_party/skia/include/private/chromium/Slug.h"
@ -108,6 +110,23 @@ sk_sp<SkData> SerializeTypeface(SkTypeface* typeface, void* ctx) {
return subset_data;
}
static sk_sp<SkTypeface> DeserializeTypeface(const void* data,
size_t length,
void* ctx) {
// TODO(bungeman,kjlubick) This should not be how the Skia deserial proc
// works.
SkStream* stream = *(reinterpret_cast<SkStream**>(const_cast<void*>(data)));
if (length < sizeof(stream)) {
return nullptr;
}
// The default implementation of SkPicture deserialization of SkTypeface
// does not use a fallback (system) font manager, but this is necessary
// on Android due to the above behavior w/r to system fonts. Thus, we
// call the underlying SkTypeface::MakeDeserialize and pass in the
// system font manager ourselves.
return SkTypeface::MakeDeserialize(stream, skia::DefaultFontMgr());
}
static bool is_supported_codec(sk_sp<SkData> data) {
CHECK(data);
return SkBmpDecoder::IsBmp(data->data(), data->size()) ||
@ -297,6 +316,7 @@ SkDeserialProcs MakeDeserialProcs(DeserializationContext* ctx) {
procs.fPictureProc = DeserializePictureAsRectData;
procs.fPictureCtx = ctx;
procs.fImageProc = DeserializeImage;
procs.fTypefaceProc = DeserializeTypeface;
sktext::gpu::Slug::AddDeserialProcs(&procs, nullptr);
return procs;
}
@ -306,6 +326,7 @@ SkDeserialProcs MakeDeserialProcs(LoadedFramesDeserialContext* ctx) {
procs.fPictureProc = GetPictureFromDeserialContext;
procs.fPictureCtx = ctx;
procs.fImageProc = DeserializeImage;
procs.fTypefaceProc = DeserializeTypeface;
return procs;
}

@ -11,7 +11,6 @@
#include "base/trace_event/trace_event.h"
#include "components/services/font/public/cpp/font_service_thread.h"
#include "pdf/buildflags.h"
#include "skia/ext/font_utils.h"
#include "third_party/skia/include/core/SkFontMgr.h"
namespace font_service {
@ -64,9 +63,10 @@ SkStreamAsset* FontLoader::openStream(const FontIdentity& identity) {
}
}
sk_sp<SkTypeface> FontLoader::makeTypeface(const FontIdentity& identity) {
sk_sp<SkTypeface> FontLoader::makeTypeface(const FontIdentity& identity,
sk_sp<SkFontMgr> mgr) {
TRACE_EVENT0("fonts", "FontServiceThread::makeTypeface");
return SkFontConfigInterface::makeTypeface(identity, skia::DefaultFontMgr());
return SkFontConfigInterface::makeTypeface(identity, mgr);
}
// Additional cross-thread accessible methods.

@ -46,7 +46,8 @@ class FontLoader : public SkFontConfigInterface,
SkString* out_family_name,
SkFontStyle* out_style) override;
SkStreamAsset* openStream(const FontIdentity& identity) override;
sk_sp<SkTypeface> makeTypeface(const FontIdentity& identity) override;
sk_sp<SkTypeface> makeTypeface(const FontIdentity& identity,
sk_sp<SkFontMgr> mgr) override;
// Additional cross-thread accessible methods below.

@ -84,6 +84,8 @@ config("skia_config") {
"SK_DISABLE_LEGACY_DEFAULT_TYPEFACE",
"SK_DISABLE_LEGACY_VULKAN_BACKENDSEMAPHORE",
"SK_DISABLE_LEGACY_CREATE_CHARACTERIZATION",
"SK_DISABLE_LEGACY_FONTMGR_REFDEFAULT",
"SK_DISABLE_LEGACY_FONTMGR_FACTORY",
]
include_dirs = [