File bad-font-gc1.patch of Package nodejs-electron
This is a revert of the commit below. While it doesn't strictly fix any
bugs, it's needed to support bad-font-gc2.patch building.
commit 9a8fc2e22363c954af239c06798bf85a9c928295
Author: Ian Kilpatrick <ikilpatrick@chromium.org>
Date: Wed Feb 14 19:35:11 2024 +0000
[gc] Make FontCustomPlatformData gc'd.
There should be no user-visible behaviour change.
Bug: 41490008
Change-Id: I6364bf4c5b5dce9f99d8e2d7e1f84537c5493c33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5293060
Commit-Queue: Ian Kilpatrick <ikilpatrick@chromium.org>
Reviewed-by: Dominik Röttsches <drott@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1260637}
--- a/third_party/blink/renderer/core/css/binary_data_font_face_source.cc
+++ b/third_party/blink/renderer/core/css/binary_data_font_face_source.cc
@@ -27,16 +27,13 @@ BinaryDataFontFaceSource::BinaryDataFont
return;
}
probe::FontsUpdated(context, font_face, String(),
- custom_platform_data_.Get());
+ custom_platform_data_.get());
}
-void BinaryDataFontFaceSource::Trace(Visitor* visitor) const {
- visitor->Trace(custom_platform_data_);
- CSSFontFaceSource::Trace(visitor);
-}
+BinaryDataFontFaceSource::~BinaryDataFontFaceSource() = default;
bool BinaryDataFontFaceSource::IsValid() const {
- return custom_platform_data_;
+ return custom_platform_data_.get();
}
SimpleFontData* BinaryDataFontFaceSource::CreateFontData(
--- a/third_party/blink/renderer/core/css/binary_data_font_face_source.h
+++ b/third_party/blink/renderer/core/css/binary_data_font_face_source.h
@@ -16,14 +16,14 @@ class FontCustomPlatformData;
class BinaryDataFontFaceSource final : public CSSFontFaceSource {
public:
BinaryDataFontFaceSource(CSSFontFace*, SharedBuffer*, String&);
- void Trace(Visitor*) const override;
+ ~BinaryDataFontFaceSource() override;
bool IsValid() const override;
private:
SimpleFontData* CreateFontData(const FontDescription&,
const FontSelectionCapabilities&) override;
- Member<const FontCustomPlatformData> custom_platform_data_;
+ scoped_refptr<FontCustomPlatformData> custom_platform_data_;
};
} // namespace blink
--- a/third_party/blink/renderer/core/css/remote_font_face_source.cc
+++ b/third_party/blink/renderer/core/css/remote_font_face_source.cc
@@ -262,7 +262,7 @@ void RemoteFontFaceSource::NotifyFinishe
FontInvalidationReason::kFontFaceLoaded);
if (custom_font_data_) {
probe::FontsUpdated(execution_context, face_->GetFontFace(),
- resource->Url().GetString(), custom_font_data_.Get());
+ resource->Url().GetString(), custom_font_data_.get());
}
}
}
@@ -456,7 +456,6 @@ void RemoteFontFaceSource::BeginLoadIfNe
void RemoteFontFaceSource::Trace(Visitor* visitor) const {
visitor->Trace(face_);
visitor->Trace(font_selector_);
- visitor->Trace(custom_font_data_);
CSSFontFaceSource::Trace(visitor);
FontResourceClient::Trace(visitor);
}
--- a/third_party/blink/renderer/core/css/remote_font_face_source.h
+++ b/third_party/blink/renderer/core/css/remote_font_face_source.h
@@ -43,7 +43,7 @@ class RemoteFontFaceSource final : publi
bool IsPendingDataUrl() const override;
const FontCustomPlatformData* GetCustomPlaftormData() const override {
- return custom_font_data_.Get();
+ return custom_font_data_.get();
}
void BeginLoadIfNeeded() override;
@@ -157,7 +157,7 @@ class RemoteFontFaceSource final : publi
Member<FontSelector> font_selector_;
// |nullptr| if font is not loaded or failed to decode.
- Member<const FontCustomPlatformData> custom_font_data_;
+ scoped_refptr<FontCustomPlatformData> custom_font_data_;
// |nullptr| if font is not loaded or failed to decode.
String url_;
--- a/third_party/blink/renderer/core/loader/resource/font_resource.cc
+++ b/third_party/blink/renderer/core/loader/resource/font_resource.cc
@@ -112,7 +112,7 @@ void FontResource::StartLoadLimitTimersI
kFontLoadWaitLong);
}
-const FontCustomPlatformData* FontResource::GetCustomFontData() {
+scoped_refptr<FontCustomPlatformData> FontResource::GetCustomFontData() {
if (!font_data_ && !ErrorOccurred() && !IsLoading()) {
if (Data()) {
auto decode_start_time = base::TimeTicks::Now();
@@ -225,7 +225,6 @@ void FontResource::AddClearDataObserver(
}
void FontResource::Trace(Visitor* visitor) const {
- visitor->Trace(font_data_);
visitor->Trace(clear_data_observers_);
Resource::Trace(visitor);
}
--- a/third_party/blink/renderer/core/loader/resource/font_resource.h
+++ b/third_party/blink/renderer/core/loader/resource/font_resource.h
@@ -72,7 +72,7 @@ class CORE_EXPORT FontResource final : p
String OtsParsingMessage() const { return ots_parsing_message_; }
- const FontCustomPlatformData* GetCustomFontData();
+ scoped_refptr<FontCustomPlatformData> GetCustomFontData();
// Returns true if the loading priority of the remote font resource can be
// lowered. The loading priority of the font can be lowered only if the
@@ -112,7 +112,7 @@ class CORE_EXPORT FontResource final : p
kMaxValue = kLongLimitExceeded,
};
- Member<FontCustomPlatformData> font_data_;
+ scoped_refptr<FontCustomPlatformData> font_data_;
String ots_parsing_message_;
LoadLimitState load_limit_state_;
bool cors_failed_;
--- a/third_party/blink/renderer/platform/fonts/font_custom_platform_data.cc
+++ b/third_party/blink/renderer/platform/fonts/font_custom_platform_data.cc
@@ -115,7 +115,7 @@ const FontPlatformData* FontCustomPlatfo
const ResolvedFontFeatures& resolved_font_features,
FontOrientation orientation,
const FontVariationSettings* variation_settings,
- const FontPalette* palette) const {
+ const FontPalette* palette) {
DCHECK(base_typeface_);
sk_sp<SkTypeface> return_typeface = base_typeface_;
@@ -304,7 +304,7 @@ String FontCustomPlatformData::FamilyNam
localized_string.fString.size());
}
-FontCustomPlatformData* FontCustomPlatformData::Create(
+scoped_refptr<FontCustomPlatformData> FontCustomPlatformData::Create(
SharedBuffer* buffer,
String& ots_parse_message) {
DCHECK(buffer);
@@ -321,8 +321,8 @@ FontCustomPlatformData* FontCustomPlatfo
if (v8::Isolate* isolate = v8::Isolate::TryGetCurrent()) {
isolate->AdjustAmountOfExternalAllocatedMemory(data_size);
}
- return MakeGarbageCollected<FontCustomPlatformData>(std::move(typeface),
- data_size);
+ return base::AdoptRef(
+ new FontCustomPlatformData(std::move(typeface), data_size));
}
bool FontCustomPlatformData::MayBeIconFont() const {
--- a/third_party/blink/renderer/platform/fonts/font_custom_platform_data.h
+++ b/third_party/blink/renderer/platform/fonts/font_custom_platform_data.h
@@ -39,7 +39,6 @@
#include "third_party/blink/renderer/platform/fonts/opentype/variable_axes_names.h"
#include "third_party/blink/renderer/platform/fonts/resolved_font_features.h"
#include "third_party/blink/renderer/platform/fonts/text_rendering_mode.h"
-#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
@@ -55,17 +54,16 @@ class FontPlatformData;
class FontVariationSettings;
class PLATFORM_EXPORT FontCustomPlatformData
- : public GarbageCollected<FontCustomPlatformData> {
+ : public RefCounted<FontCustomPlatformData> {
+ USING_FAST_MALLOC(FontCustomPlatformData);
+
public:
- static FontCustomPlatformData* Create(SharedBuffer*,
- String& ots_parse_message);
- FontCustomPlatformData(sk_sp<SkTypeface>, size_t data_size);
+ static scoped_refptr<FontCustomPlatformData> Create(SharedBuffer*,
+ String& ots_parse_message);
FontCustomPlatformData(const FontCustomPlatformData&) = delete;
FontCustomPlatformData& operator=(const FontCustomPlatformData&) = delete;
~FontCustomPlatformData();
- void Trace(Visitor*) const {}
-
// The size argument should come from EffectiveFontSize() and
// adjusted_specified_size should come from AdjustedSpecifiedSize() of
// FontDescription. The latter is needed for correctly applying
@@ -82,7 +80,7 @@ class PLATFORM_EXPORT FontCustomPlatform
const ResolvedFontFeatures& resolved_font_features,
FontOrientation = FontOrientation::kHorizontal,
const FontVariationSettings* = nullptr,
- const FontPalette* = nullptr) const;
+ const FontPalette* = nullptr);
String FamilyNameForInspector() const;
@@ -93,6 +91,7 @@ class PLATFORM_EXPORT FontCustomPlatform
bool MayBeIconFont() const;
private:
+ FontCustomPlatformData(sk_sp<SkTypeface>, size_t data_size);
sk_sp<SkTypeface> base_typeface_;
size_t data_size_;
--- a/third_party/blink/renderer/platform/testing/font_test_helpers.cc
+++ b/third_party/blink/renderer/platform/testing/font_test_helpers.cc
@@ -29,7 +29,7 @@ class TestFontSelector : public FontSele
static TestFontSelector* Create(const uint8_t* data, size_t size) {
scoped_refptr<SharedBuffer> font_buffer = SharedBuffer::Create(data, size);
String ots_parse_message;
- FontCustomPlatformData* font_custom_platform_data =
+ scoped_refptr<FontCustomPlatformData> font_custom_platform_data =
FontCustomPlatformData::Create(font_buffer.get(), ots_parse_message);
if (!font_custom_platform_data)
return nullptr;
@@ -37,17 +37,12 @@ class TestFontSelector : public FontSele
std::move(font_custom_platform_data));
}
- TestFontSelector(FontCustomPlatformData* custom_platform_data)
- : custom_platform_data_(custom_platform_data) {
+ TestFontSelector(scoped_refptr<FontCustomPlatformData> custom_platform_data)
+ : custom_platform_data_(std::move(custom_platform_data)) {
DCHECK(custom_platform_data_);
}
~TestFontSelector() override = default;
- void Trace(Visitor* visitor) const override {
- visitor->Trace(custom_platform_data_);
- FontSelector::Trace(visitor);
- }
-
FontData* GetFontData(const FontDescription& font_description,
const FontFamily&) override {
FontSelectionCapabilities normal_capabilities(
@@ -117,7 +112,7 @@ class TestFontSelector : public FontSele
}
private:
- Member<FontCustomPlatformData> custom_platform_data_;
+ scoped_refptr<FontCustomPlatformData> custom_platform_data_;
};
} // namespace