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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/FontFallbackIterator.cpp

Issue 2066253002: Fix Refcount in FontDataCache for objects from FontFallbackIterator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 months 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "platform/fonts/FontFallbackIterator.h" 5 #include "platform/fonts/FontFallbackIterator.h"
6 6
7 #include "platform/Logging.h" 7 #include "platform/Logging.h"
8 #include "platform/fonts/FontCache.h" 8 #include "platform/fonts/FontCache.h"
9 #include "platform/fonts/FontDescription.h" 9 #include "platform/fonts/FontDescription.h"
10 #include "platform/fonts/FontFallbackList.h" 10 #include "platform/fonts/FontFallbackList.h"
(...skipping 29 matching lines...) Expand all
40 return false; 40 return false;
41 } 41 }
42 42
43 const FontData* fontData = m_fontFallbackList->fontDataAt(m_fontDescription, m_currentFontDataIndex); 43 const FontData* fontData = m_fontFallbackList->fontDataAt(m_fontDescription, m_currentFontDataIndex);
44 return fontData && fontData->isSegmented(); 44 return fontData && fontData->isSegmented();
45 } 45 }
46 46
47 bool FontFallbackIterator::alreadyLoadingRangeForHintChar(UChar32 hintChar) 47 bool FontFallbackIterator::alreadyLoadingRangeForHintChar(UChar32 hintChar)
48 { 48 {
49 for (auto it = m_trackedLoadingRangeSets.begin(); it != m_trackedLoadingRang eSets.end(); ++it) { 49 for (auto it = m_trackedLoadingRangeSets.begin(); it != m_trackedLoadingRang eSets.end(); ++it) {
50 if (it->contains(hintChar)) 50 if ((*it)->contains(hintChar))
51 return true; 51 return true;
52 } 52 }
53 return false; 53 return false;
54 } 54 }
55 55
56 bool FontFallbackIterator::rangeSetContributesForHint(const Vector<UChar32> hint List, const FontDataForRangeSet& segmentedFace) 56 bool FontFallbackIterator::rangeSetContributesForHint(const Vector<UChar32> hint List, const FontDataForRangeSet* segmentedFace)
57 { 57 {
58 for (auto it = hintList.begin(); it != hintList.end(); ++it) { 58 for (auto it = hintList.begin(); it != hintList.end(); ++it) {
59 if (segmentedFace.contains(*it)) { 59 if (segmentedFace->contains(*it)) {
60 if (!alreadyLoadingRangeForHintChar(*it)) 60 if (!alreadyLoadingRangeForHintChar(*it))
61 return true; 61 return true;
62 } 62 }
63 } 63 }
64 return false; 64 return false;
65 } 65 }
66 66
67 void FontFallbackIterator::willUseRange(const AtomicString& family, const FontDa taForRangeSet& rangeSet) 67 void FontFallbackIterator::willUseRange(const AtomicString& family, const FontDa taForRangeSet& rangeSet)
68 { 68 {
69 FontSelector* selector = m_fontFallbackList->getFontSelector(); 69 FontSelector* selector = m_fontFallbackList->getFontSelector();
70 if (!selector) 70 if (!selector)
71 return; 71 return;
72 72
73 selector->willUseRange(m_fontDescription, family, rangeSet); 73 selector->willUseRange(m_fontDescription, family, rangeSet);
74 } 74 }
75 75
76 const FontDataForRangeSet FontFallbackIterator::next(const Vector<UChar32>& hint List) 76 const PassRefPtr<FontDataForRangeSet> FontFallbackIterator::next(const Vector<UC har32>& hintList)
77 { 77 {
78 if (m_fallbackStage == OutOfLuck) 78 if (m_fallbackStage == OutOfLuck)
79 return FontDataForRangeSet(); 79 return adoptRef(new FontDataForRangeSet());
80 80
81 if (m_fallbackStage == FallbackPriorityFonts) { 81 if (m_fallbackStage == FallbackPriorityFonts) {
82 // Only try one fallback priority font, 82 // Only try one fallback priority font,
83 // then proceed to regular system fallback. 83 // then proceed to regular system fallback.
84 m_fallbackStage = SystemFonts; 84 m_fallbackStage = SystemFonts;
85 FontDataForRangeSet fallbackPriorityFontRange(fallbackPriorityFont(hintL ist[0])); 85 RefPtr<FontDataForRangeSet> fallbackPriorityFontRange = adoptRef(new Fon tDataForRangeSet(fallbackPriorityFont(hintList[0])));
86 if (fallbackPriorityFontRange.hasFontData()) 86 if (fallbackPriorityFontRange->hasFontData())
87 return fallbackPriorityFontRange; 87 return fallbackPriorityFontRange.release();
88 return next(hintList); 88 return next(hintList);
89 } 89 }
90 90
91 if (m_fallbackStage == SystemFonts) { 91 if (m_fallbackStage == SystemFonts) {
92 // We've reached pref + system fallback. 92 // We've reached pref + system fallback.
93 ASSERT(hintList.size()); 93 ASSERT(hintList.size());
94 RefPtr<SimpleFontData> systemFont = uniqueSystemFontForHint(hintList[0]) ; 94 RefPtr<SimpleFontData> systemFont = uniqueSystemFontForHint(hintList[0]) ;
95 if (systemFont) 95 if (systemFont) {
96 return FontDataForRangeSet(systemFont); 96 // Fallback fonts are not retained in the FontDataCache.
97 return adoptRef(new FontDataForRangeSet(systemFont));
98 }
97 99
98 // If we don't have options from the system fallback anymore or had 100 // If we don't have options from the system fallback anymore or had
99 // previously returned them, we only have the last resort font left. 101 // previously returned them, we only have the last resort font left.
100 // TODO: crbug.com/42217 Improve this by doing the last run with a last 102 // TODO: crbug.com/42217 Improve this by doing the last run with a last
101 // resort font that has glyphs for everything, for example the Unicode 103 // resort font that has glyphs for everything, for example the Unicode
102 // LastResort font, not just Times or Arial. 104 // LastResort font, not just Times or Arial.
103 FontCache* fontCache = FontCache::fontCache(); 105 FontCache* fontCache = FontCache::fontCache();
104 m_fallbackStage = OutOfLuck; 106 m_fallbackStage = OutOfLuck;
105 RefPtr<SimpleFontData> lastResort = fontCache->getLastResortFallbackFont (m_fontDescription).get(); 107 RefPtr<SimpleFontData> lastResort = fontCache->getLastResortFallbackFont (m_fontDescription).get();
106 RELEASE_ASSERT(lastResort); 108 RELEASE_ASSERT(lastResort);
107 return FontDataForRangeSet(lastResort); 109 return adoptRef(new FontDataForRangeSetFromCache(lastResort));
108 } 110 }
109 111
110 ASSERT(m_fallbackStage == FontGroupFonts 112 ASSERT(m_fallbackStage == FontGroupFonts
111 || m_fallbackStage == SegmentedFace); 113 || m_fallbackStage == SegmentedFace);
112 const FontData* fontData = m_fontFallbackList->fontDataAt( 114 const FontData* fontData = m_fontFallbackList->fontDataAt(
113 m_fontDescription, m_currentFontDataIndex); 115 m_fontDescription, m_currentFontDataIndex);
114 116
115 if (!fontData) { 117 if (!fontData) {
116 // If there is no fontData coming from the fallback list, it means 118 // If there is no fontData coming from the fallback list, it means
117 // we are now looking at system fonts, either for prioritized symbol 119 // we are now looking at system fonts, either for prioritized symbol
118 // or emoji fonts or by calling system fallback API. 120 // or emoji fonts or by calling system fallback API.
119 m_fallbackStage = isNonTextFallbackPriority(m_fontFallbackPriority) 121 m_fallbackStage = isNonTextFallbackPriority(m_fontFallbackPriority)
120 ? FallbackPriorityFonts 122 ? FallbackPriorityFonts
121 : SystemFonts; 123 : SystemFonts;
122 return next(hintList); 124 return next(hintList);
123 } 125 }
124 126
125 // Otherwise we've received a fontData from the font-family: set of fonts, 127 // Otherwise we've received a fontData from the font-family: set of fonts,
126 // and a non-segmented one in this case. 128 // and a non-segmented one in this case.
127 if (!fontData->isSegmented()) { 129 if (!fontData->isSegmented()) {
128 // Skip forward to the next font family for the next call to next(). 130 // Skip forward to the next font family for the next call to next().
129 m_currentFontDataIndex++; 131 m_currentFontDataIndex++;
130 if (!fontData->isLoading()) { 132 if (!fontData->isLoading()) {
131 RefPtr<SimpleFontData> nonSegmented = const_cast<SimpleFontData*>(to SimpleFontData(fontData)); 133 RefPtr<SimpleFontData> nonSegmented = const_cast<SimpleFontData*>(to SimpleFontData(fontData));
132 return FontDataForRangeSet(nonSegmented); 134 // The fontData object that we have here is tracked in m_fontList of
135 // FontFallbackList and gets released in the font cache when the
136 // FontFallbackList is destroyed.
137 return adoptRef(new FontDataForRangeSet(nonSegmented));
133 } 138 }
134 return next(hintList); 139 return next(hintList);
135 } 140 }
136 141
137 // Iterate over ranges of a segmented font below. 142 // Iterate over ranges of a segmented font below.
138 143
139 const SegmentedFontData* segmented = toSegmentedFontData(fontData); 144 const SegmentedFontData* segmented = toSegmentedFontData(fontData);
140 if (m_fallbackStage != SegmentedFace) { 145 if (m_fallbackStage != SegmentedFace) {
141 m_segmentedFaceIndex = 0; 146 m_segmentedFaceIndex = 0;
142 m_fallbackStage = SegmentedFace; 147 m_fallbackStage = SegmentedFace;
143 } 148 }
144 149
145 ASSERT(m_segmentedFaceIndex < segmented->numFaces()); 150 ASSERT(m_segmentedFaceIndex < segmented->numFaces());
146 FontDataForRangeSet currentSegmentedFace = segmented->faceAt(m_segmentedFace Index); 151 RefPtr<FontDataForRangeSet> currentSegmentedFace = segmented->faceAt(m_segme ntedFaceIndex);
147 m_segmentedFaceIndex++; 152 m_segmentedFaceIndex++;
148 153
149 if (m_segmentedFaceIndex == segmented->numFaces()) { 154 if (m_segmentedFaceIndex == segmented->numFaces()) {
150 // Switch from iterating over a segmented face to the next family from 155 // Switch from iterating over a segmented face to the next family from
151 // the font-family: group of fonts. 156 // the font-family: group of fonts.
152 m_fallbackStage = FontGroupFonts; 157 m_fallbackStage = FontGroupFonts;
153 m_currentFontDataIndex++; 158 m_currentFontDataIndex++;
154 } 159 }
155 160
156 if (rangeSetContributesForHint(hintList, currentSegmentedFace)) { 161 if (rangeSetContributesForHint(hintList, currentSegmentedFace.get())) {
157 const SimpleFontData* fontData = currentSegmentedFace.fontData(); 162 const SimpleFontData* fontData = currentSegmentedFace->fontData();
158 if (const CustomFontData* customFontData = fontData->customFontData()) 163 if (const CustomFontData* customFontData = fontData->customFontData())
159 customFontData->beginLoadIfNeeded(); 164 customFontData->beginLoadIfNeeded();
160 if (!fontData->isLoading()) 165 if (!fontData->isLoading())
161 return currentSegmentedFace; 166 return currentSegmentedFace;
162 m_trackedLoadingRangeSets.append(currentSegmentedFace); 167 m_trackedLoadingRangeSets.append(currentSegmentedFace);
163 } 168 }
164 169
165 return next(hintList); 170 return next(hintList);
166 } 171 }
167 172
(...skipping 15 matching lines...) Expand all
183 // because the shaper must have previously tried shaping with the font 188 // because the shaper must have previously tried shaping with the font
184 // already. 189 // already.
185 if (m_previouslyAskedForHint.contains(hint)) 190 if (m_previouslyAskedForHint.contains(hint))
186 return nullptr; 191 return nullptr;
187 192
188 m_previouslyAskedForHint.add(hint); 193 m_previouslyAskedForHint.add(hint);
189 return fontCache->fallbackFontForCharacter(m_fontDescription, hint, m_fontFa llbackList->primarySimpleFontData(m_fontDescription)); 194 return fontCache->fallbackFontForCharacter(m_fontDescription, hint, m_fontFa llbackList->primarySimpleFontData(m_fontDescription));
190 } 195 }
191 196
192 } // namespace blink 197 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698