Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(749)

Side by Side Diff: third_party/WebKit/Source/core/css/RemoteFontFaceSource.cpp

Issue 1429713004: Implement CSS font-display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: failure does not mean loaded Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->didBecomeVisibleFallback(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
94 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescri ption& fontDescription) 123 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createFontData(const FontDescri ption& fontDescription)
95 { 124 {
96 if (!isLoaded()) 125 if (!isLoaded())
97 return createLoadingFallbackFontData(fontDescription); 126 return createLoadingFallbackFontData(fontDescription);
98 127
99 // Create new FontPlatformData from our CGFontRef, point size and ATSFontRef . 128 if (!m_font->ensureCustomFontData() || m_period == FailurePeriod)
100 if (!m_font->ensureCustomFontData())
101 return nullptr; 129 return nullptr;
102 130
103 m_histograms.recordFallbackTime(m_font.get()); 131 m_histograms.recordFallbackTime(m_font.get());
104 132
105 return SimpleFontData::create( 133 return SimpleFontData::create(
106 m_font->platformDataFromCustomData(fontDescription.effectiveFontSize(), 134 m_font->platformDataFromCustomData(fontDescription.effectiveFontSize(),
107 fontDescription.isSyntheticBold(), fontDescription.isSyntheticItalic (), 135 fontDescription.isSyntheticBold(), fontDescription.isSyntheticItalic (),
108 fontDescription.orientation()), CustomFontData::create()); 136 fontDescription.orientation()), CustomFontData::create());
109 } 137 }
110 138
111 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createLoadingFallbackFontData(c onst FontDescription& fontDescription) 139 PassRefPtr<SimpleFontData> RemoteFontFaceSource::createLoadingFallbackFontData(c onst FontDescription& fontDescription)
112 { 140 {
113 // This temporary font is not retained and should not be returned. 141 // This temporary font is not retained and should not be returned.
114 FontCachePurgePreventer fontCachePurgePreventer; 142 FontCachePurgePreventer fontCachePurgePreventer;
115 SimpleFontData* temporaryFont = FontCache::fontCache()->getNonRetainedLastRe sortFallbackFont(fontDescription); 143 SimpleFontData* temporaryFont = FontCache::fontCache()->getNonRetainedLastRe sortFallbackFont(fontDescription);
116 if (!temporaryFont) { 144 if (!temporaryFont) {
117 ASSERT_NOT_REACHED(); 145 ASSERT_NOT_REACHED();
118 return nullptr; 146 return nullptr;
119 } 147 }
120 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(this, m_fo nt->exceedsFontLoadWaitLimit() ? CSSCustomFontData::VisibleFallback : CSSCustomF ontData::InvisibleFallback); 148 RefPtr<CSSCustomFontData> cssFontData = CSSCustomFontData::create(this, m_pe riod == BlockPeriod ? CSSCustomFontData::InvisibleFallback : CSSCustomFontData:: VisibleFallback);
121 return SimpleFontData::create(temporaryFont->platformData(), cssFontData); 149 return SimpleFontData::create(temporaryFont->platformData(), cssFontData);
122 } 150 }
123 151
124 void RemoteFontFaceSource::beginLoadIfNeeded() 152 void RemoteFontFaceSource::beginLoadIfNeeded()
125 { 153 {
126 if (m_font->stillNeedsLoad()) 154 if (m_font->stillNeedsLoad())
127 m_fontLoader->addFontToBeginLoading(m_font.get()); 155 m_fontLoader->addFontToBeginLoading(m_font.get());
128 156
129 if (m_face) 157 if (m_face)
130 m_face->didBeginLoad(); 158 m_face->didBeginLoad();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 if (size < 50 * 1024) 215 if (size < 50 * 1024)
188 return "WebFont.DownloadTime.1.10KBTo50KB"; 216 return "WebFont.DownloadTime.1.10KBTo50KB";
189 if (size < 100 * 1024) 217 if (size < 100 * 1024)
190 return "WebFont.DownloadTime.2.50KBTo100KB"; 218 return "WebFont.DownloadTime.2.50KBTo100KB";
191 if (size < 1024 * 1024) 219 if (size < 1024 * 1024)
192 return "WebFont.DownloadTime.3.100KBTo1MB"; 220 return "WebFont.DownloadTime.3.100KBTo1MB";
193 return "WebFont.DownloadTime.4.Over1MB"; 221 return "WebFont.DownloadTime.4.Over1MB";
194 } 222 }
195 223
196 } // namespace blink 224 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698