1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
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
|