OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/css/RemoteFontFaceSource.h" | 6 #include "core/css/RemoteFontFaceSource.h" |
7 | 7 |
8 #include "core/css/CSSCustomFontData.h" | 8 #include "core/css/CSSCustomFontData.h" |
9 #include "core/css/CSSFontFace.h" | 9 #include "core/css/CSSFontFace.h" |
10 #include "core/css/FontLoader.h" | 10 #include "core/css/FontLoader.h" |
11 #include "platform/fonts/FontCache.h" | 11 #include "platform/fonts/FontCache.h" |
12 #include "platform/fonts/FontDescription.h" | 12 #include "platform/fonts/FontDescription.h" |
13 #include "platform/fonts/SimpleFontData.h" | 13 #include "platform/fonts/SimpleFontData.h" |
14 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
15 #include "wtf/CurrentTime.h" | 15 #include "wtf/CurrentTime.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, PassRefPtrWillBeR awPtr<FontLoader> fontLoader) | 19 RemoteFontFaceSource::RemoteFontFaceSource(FontResource* font, PassRefPtrWillBeR awPtr<FontLoader> fontLoader, FontDisplay display) |
20 : m_font(font) | 20 : m_font(font) |
21 , m_fontLoader(fontLoader) | 21 , m_fontLoader(fontLoader) |
22 , m_display(display) | |
23 , m_period(display == FontDisplaySwap ? SwapPeriod : BlockPeriod) | |
22 { | 24 { |
23 m_font->addClient(this); | 25 m_font->addClient(this); |
24 } | 26 } |
25 | 27 |
26 RemoteFontFaceSource::~RemoteFontFaceSource() | 28 RemoteFontFaceSource::~RemoteFontFaceSource() |
27 { | 29 { |
28 m_font->removeClient(this); | 30 m_font->removeClient(this); |
29 pruneTable(); | 31 pruneTable(); |
30 } | 32 } |
31 | 33 |
32 void RemoteFontFaceSource::pruneTable() | 34 void RemoteFontFaceSource::pruneTable() |
33 { | 35 { |
34 if (m_fontDataTable.isEmpty()) | 36 if (m_fontDataTable.isEmpty()) |
35 return; | 37 return; |
36 | 38 |
37 for (const auto& item : m_fontDataTable) { | 39 for (const auto& item : m_fontDataTable) { |
38 SimpleFontData* fontData = item.value.get(); | 40 SimpleFontData* fontData = item.value.get(); |
39 if (fontData && fontData->customFontData()) | 41 if (fontData && fontData->customFontData()) |
40 fontData->customFontData()->clearFontFaceSource(); | 42 fontData->customFontData()->clearFontFaceSource(); |
41 } | 43 } |
42 m_fontDataTable.clear(); | 44 m_fontDataTable.clear(); |
43 } | 45 } |
44 | 46 |
45 bool RemoteFontFaceSource::isLoading() const | 47 bool RemoteFontFaceSource::isLoading() const |
46 { | 48 { |
47 return !m_font->stillNeedsLoad() && !m_font->isLoaded(); | 49 return m_period != FailurePeriod && !m_font->stillNeedsLoad() && !m_font->is Loaded(); |
48 } | 50 } |
49 | 51 |
50 bool RemoteFontFaceSource::isLoaded() const | 52 bool RemoteFontFaceSource::isLoaded() const |
51 { | 53 { |
52 return m_font->isLoaded(); | 54 return m_period == FailurePeriod || m_font->isLoaded(); |
Yoav Weiss
2015/11/02 08:57:28
So failure is defined as loaded? Can you add a lin
Kunihiko Sakamoto
2015/11/04 02:32:51
This is to make the RemoteFontFaceSource behave as
Kunihiko Sakamoto
2015/11/17 05:47:43
Changed it not to treat failure period as loaded,
| |
53 } | 55 } |
54 | 56 |
55 bool RemoteFontFaceSource::isValid() const | 57 bool RemoteFontFaceSource::isValid() const |
56 { | 58 { |
57 return !m_font->errorOccurred(); | 59 return m_period != FailurePeriod && !m_font->errorOccurred(); |
58 } | 60 } |
59 | 61 |
60 void RemoteFontFaceSource::didStartFontLoad(FontResource*) | 62 void RemoteFontFaceSource::didStartFontLoad(FontResource*) |
61 { | 63 { |
62 // We may send duplicated reports when multiple CSSFontFaceSource are | 64 // We may send duplicated reports when multiple CSSFontFaceSource are |
63 // registered at this FontResource. Associating the same URL to different | 65 // registered at this FontResource. Associating the same URL to different |
64 // font-family causes the case, but we treat them as indivisual resources. | 66 // font-family causes the case, but we treat them as indivisual resources. |
65 m_histograms.loadStarted(); | 67 m_histograms.loadStarted(); |
66 } | 68 } |
67 | 69 |
68 void RemoteFontFaceSource::fontLoaded(FontResource*) | 70 void RemoteFontFaceSource::fontLoaded(FontResource*) |
69 { | 71 { |
70 m_histograms.recordRemoteFont(m_font.get()); | 72 m_histograms.recordRemoteFont(m_font.get()); |
71 | 73 |
72 m_font->ensureCustomFontData(); | 74 m_font->ensureCustomFontData(); |
73 if (m_font->status() == Resource::DecodeError) | 75 if (m_font->status() == Resource::DecodeError) |
74 m_fontLoader->didFailToDecode(m_font.get()); | 76 m_fontLoader->didFailToDecode(m_font.get()); |
75 | 77 |
76 pruneTable(); | 78 pruneTable(); |
77 if (m_face) { | 79 if (m_face) { |
78 m_fontLoader->fontFaceInvalidated(); | 80 m_fontLoader->fontFaceInvalidated(); |
79 m_face->fontLoaded(this); | 81 m_face->fontLoaded(this); |
80 } | 82 } |
81 } | 83 } |
82 | 84 |
83 void RemoteFontFaceSource::fontLoadWaitLimitExceeded(FontResource*) | 85 void RemoteFontFaceSource::fontLoadShortLimitExceeded(FontResource*) |
84 { | 86 { |
87 if (m_display == FontDisplayFallback) | |
88 switchToSwapPeriod(); | |
89 else if (m_display == FontDisplayOptional) | |
90 switchToFailurePeriod(); | |
91 } | |
92 | |
93 void RemoteFontFaceSource::fontLoadLongLimitExceeded(FontResource*) | |
94 { | |
95 if (m_display == FontDisplayAuto || m_display == FontDisplayBlock) | |
96 switchToSwapPeriod(); | |
97 else if (m_display == FontDisplayFallback) | |
98 switchToFailurePeriod(); | |
99 } | |
100 | |
101 void RemoteFontFaceSource::switchToSwapPeriod() | |
102 { | |
103 ASSERT(m_period == BlockPeriod); | |
104 m_period = SwapPeriod; | |
105 | |
85 pruneTable(); | 106 pruneTable(); |
86 if (m_face) { | 107 if (m_face) { |
87 m_fontLoader->fontFaceInvalidated(); | 108 m_fontLoader->fontFaceInvalidated(); |
88 m_face->fontLoadWaitLimitExceeded(this); | 109 m_face->fontDataInvalidated(this); |
89 } | 110 } |
90 | 111 |
91 m_histograms.recordFallbackTime(m_font.get()); | 112 m_histograms.recordFallbackTime(m_font.get()); |
92 } | 113 } |
93 | 114 |
115 void RemoteFontFaceSource::switchToFailurePeriod() | |
116 { | |
117 if (m_period == BlockPeriod) | |
118 switchToSwapPeriod(); | |
119 ASSERT(m_period == SwapPeriod); | |
120 m_period = FailurePeriod; | |
121 | |
122 pruneTable(); | |
123 if (m_face) { | |
124 m_fontLoader->fontFaceInvalidated(); | |
125 m_face->fontLoaded(this); | |
126 } | |
127 } | |
128 | |
94 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescri ption& fontDescription) | 129 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescri ption& fontDescription) |
95 { | 130 { |
96 if (!isLoaded()) | 131 if (!isLoaded()) |
97 return createLoadingFallbackFontData(fontDescription); | 132 return createLoadingFallbackFontData(fontDescription); |
98 | 133 |
99 // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef . | 134 // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef . |
100 if (!m_font->ensureCustomFontData()) | 135 if (!m_font->ensureCustomFontData()) |
101 return nullptr; | 136 return nullptr; |
102 | 137 |
103 m_histograms.recordFallbackTime(m_font.get()); | 138 m_histograms.recordFallbackTime(m_font.get()); |
104 | 139 |
105 return SimpleFontData::create( | 140 return SimpleFontData::create( |
106 m_font->platformDataFromCustomData(fontDescription.effectiveFontSize(), | 141 m_font->platformDataFromCustomData(fontDescription.effectiveFontSize(), |
107 fontDescription.isSyntheticBold(), fontDescription.isSyntheticItalic (), | 142 fontDescription.isSyntheticBold(), fontDescription.isSyntheticItalic (), |
108 fontDescription.orientation()), CustomFontData::create()); | 143 fontDescription.orientation()), CustomFontData::create()); |
109 } | 144 } |
110 | 145 |
111 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createLoadingFallbackFontData(c onst FontDescription& fontDescription) | 146 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createLoadingFallbackFontData(c onst FontDescription& fontDescription) |
112 { | 147 { |
113 // This temporary font is not retained and should not be returned. | 148 // This temporary font is not retained and should not be returned. |
114 FontCachePurgePreventer fontCachePurgePreventer; | 149 FontCachePurgePreventer fontCachePurgePreventer; |
115 SimpleFontData* temporaryFont = FontCache::fontCache()->getNonRetainedLastRe sortFallbackFont(fontDescription); | 150 SimpleFontData* temporaryFont = FontCache::fontCache()->getNonRetainedLastRe sortFallbackFont(fontDescription); |
116 if (!temporaryFont) { | 151 if (!temporaryFont) { |
117 ASSERT_NOT_REACHED(); | 152 ASSERT_NOT_REACHED(); |
118 return nullptr; | 153 return nullptr; |
119 } | 154 } |
120 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(this, m_fo nt->exceedsFontLoadWaitLimit() ? CSSCustomFontData::VisibleFallback : CSSCustomF ontData::InvisibleFallback); | 155 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(this, m_pe riod == BlockPeriod ? CSSCustomFontData::InvisibleFallback : CSSCustomFontData:: VisibleFallback); |
121 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); | 156 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); |
122 } | 157 } |
123 | 158 |
124 void RemoteFontFaceSource::beginLoadIfNeeded() | 159 void RemoteFontFaceSource::beginLoadIfNeeded() |
125 { | 160 { |
126 if (m_font->stillNeedsLoad()) | 161 if (m_font->stillNeedsLoad()) |
127 m_fontLoader->addFontToBeginLoading(m_font.get()); | 162 m_fontLoader->addFontToBeginLoading(m_font.get()); |
128 | 163 |
129 if (m_face) | 164 if (m_face) |
130 m_face->didBeginLoad(); | 165 m_face->didBeginLoad(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 if (size < 50 * 1024) | 222 if (size < 50 * 1024) |
188 return "WebFont.DownloadTime.1.10KBTo50KB"; | 223 return "WebFont.DownloadTime.1.10KBTo50KB"; |
189 if (size < 100 * 1024) | 224 if (size < 100 * 1024) |
190 return "WebFont.DownloadTime.2.50KBTo100KB"; | 225 return "WebFont.DownloadTime.2.50KBTo100KB"; |
191 if (size < 1024 * 1024) | 226 if (size < 1024 * 1024) |
192 return "WebFont.DownloadTime.3.100KBTo1MB"; | 227 return "WebFont.DownloadTime.3.100KBTo1MB"; |
193 return "WebFont.DownloadTime.4.Over1MB"; | 228 return "WebFont.DownloadTime.4.Over1MB"; |
194 } | 229 } |
195 | 230 |
196 } // namespace blink | 231 } // namespace blink |
OLD | NEW |