Changeset 178250 in webkit
- Timestamp:
- Jan 11, 2015 2:58:09 PM (9 years ago)
- Location:
- trunk/Source
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r178249 r178250 1 2015-01-11 Antti Koivisto <antti@apple.com> 2 3 Remove FontCachePurgePreventer 4 https://bugs.webkit.org/show_bug.cgi?id=139628 5 6 Reviewed by Anders Carlsson. 7 8 This stack type is bug prone and invasive. A missing FontCachePurgePreventer in a code that touches fonts is always 9 a hard-to-detect bug and there are many places that need it. Instead purge the font cache on top of the runloop. 10 11 The purge timer could in principle fire in a nested runloop. However we should never have unreferenced 12 SimpleFontData objects in the stack in such case (GlyphData objects don't currently ref the font) because those 13 only occur during layout and painting. Layout and painting can't trigger a nested runloops as there would be 14 bigger problems. 15 16 Purging may also be triggered synchronously by a memory notification. That case won't have any GlyphDatas in the stack either. 17 18 * html/canvas/CanvasRenderingContext2D.cpp: 19 (WebCore::CanvasRenderingContext2D::measureText): 20 (WebCore::CanvasRenderingContext2D::drawTextInternal): 21 * page/FrameView.cpp: 22 (WebCore::FrameView::layout): 23 (WebCore::FrameView::paintContents): 24 * platform/graphics/FontCache.cpp: 25 (WebCore::FontCache::FontCache): 26 (WebCore::FontCache::fontForFamily): 27 (WebCore::FontCache::purgeTimerFired): 28 (WebCore::FontCache::purgeInactiveFontData): 29 * platform/graphics/FontCache.h: 30 (WebCore::FontCache::disablePurging): Deleted. 31 (WebCore::FontCache::enablePurging): Deleted. 32 (WebCore::FontCachePurgePreventer::FontCachePurgePreventer): Deleted. 33 (WebCore::FontCachePurgePreventer::~FontCachePurgePreventer): Deleted. 34 * platform/graphics/FontFastPath.cpp: 35 (WebCore::Font::emphasisMarkAscent): 36 (WebCore::Font::emphasisMarkDescent): 37 (WebCore::Font::emphasisMarkHeight): 38 (WebCore::Font::drawEmphasisMarks): 39 * platform/graphics/ca/win/PlatformCALayerWinInternal.cpp: 40 (PlatformCALayerWinInternal::displayCallback): 41 * platform/mac/DragImageMac.mm: 42 (WebCore::widthWithFont): 43 (WebCore::drawAtPoint): 44 (WebCore::createDragImageForLink): 45 * platform/win/DragImageWin.cpp: 46 (WebCore::createDragImageForLink): 47 * platform/win/WebCoreTextRenderer.cpp: 48 (WebCore::doDrawTextAtPoint): 49 (WebCore::WebCoreTextFloatWidth): 50 * rendering/InlineTextBox.cpp: 51 (WebCore::InlineTextBox::localSelectionRect): 52 (WebCore::InlineTextBox::offsetForPosition): 53 (WebCore::InlineTextBox::positionForOffset): 54 * rendering/RenderImage.cpp: 55 (WebCore::RenderImage::setImageSizeForAltText): 56 * rendering/RenderLayerBacking.cpp: 57 (WebCore::RenderLayerBacking::paintIntoLayer): 58 * rendering/RenderListBox.cpp: 59 (WebCore::RenderListBox::updateFromElement): 60 (WebCore::RenderListBox::paintItemForeground): 61 * rendering/RenderMenuList.cpp: 62 (RenderMenuList::updateOptionsWidth): 63 * rendering/RenderThemeIOS.mm: 64 (WebCore::adjustInputElementButtonStyle): 65 * rendering/mathml/RenderMathMLOperator.cpp: 66 (WebCore::RenderMathMLOperator::updateStyle): 67 * rendering/svg/RenderSVGText.cpp: 68 (WebCore::RenderSVGText::subtreeChildWasAdded): 69 (WebCore::RenderSVGText::subtreeStyleDidChange): 70 (WebCore::RenderSVGText::subtreeTextDidChange): 71 (WebCore::RenderSVGText::removeChild): 72 * rendering/svg/SVGInlineTextBox.cpp: 73 (WebCore::SVGInlineTextBox::selectionRectForTextFragment): 74 1 75 2015-01-11 Myles C. Maxfield <mmaxfield@apple.com> 2 76 -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r174676 r178250 43 43 #include "ExceptionCodePlaceholder.h" 44 44 #include "FloatQuad.h" 45 #include "FontCache.h"46 45 #include "GraphicsContext.h" 47 46 #include "HTMLImageElement.h" … … 2258 2257 PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text) 2259 2258 { 2260 FontCachePurgePreventer fontCachePurgePreventer;2261 2262 2259 RefPtr<TextMetrics> metrics = TextMetrics::create(); 2263 2260 … … 2290 2287 if (fill && gradient && gradient->isZeroSize()) 2291 2288 return; 2292 2293 FontCachePurgePreventer fontCachePurgePreventer;2294 2289 2295 2290 const Font& font = accessFont(); -
trunk/Source/WebCore/page/FrameView.cpp
r178038 r178250 41 41 #include "FloatRect.h" 42 42 #include "FocusController.h" 43 #include "FontCache.h"44 43 #include "FontLoader.h" 45 44 #include "FrameLoader.h" … … 1223 1222 } 1224 1223 1225 FontCachePurgePreventer fontCachePurgePreventer;1226 1224 RenderLayer* layer; 1227 1225 … … 3847 3845 willPaintContents(context, dirtyRect, paintingState); 3848 3846 3849 FontCachePurgePreventer fontCachePurgePreventer;3850 3851 3847 // m_nodeToDraw is used to draw only one element (and its descendants) 3852 3848 RenderObject* renderer = m_nodeToDraw ? m_nodeToDraw->renderer() : nullptr; -
trunk/Source/WebCore/platform/graphics/FontCache.cpp
r178180 r178250 94 94 95 95 FontCache::FontCache() 96 : m_purge PreventCount(0)96 : m_purgeTimer(*this, &FontCache::purgeTimerFired) 97 97 { 98 98 } … … 373 373 const int cTargetInactiveFontData = 100; 374 374 #else 375 const int cMaxInactiveFontData = 225;375 const int cMaxInactiveFontData = 5; 376 376 const int cTargetInactiveFontData = 200; 377 377 #endif … … 382 382 RefPtr<SimpleFontData> FontCache::fontForFamily(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName) 383 383 { 384 if (!m_purgeTimer.isActive()) 385 m_purgeTimer.startOneShot(std::chrono::milliseconds::zero()); 386 384 387 FontPlatformData* platformData = getCachedFontPlatformData(fontDescription, family, checkingAlternateName); 385 388 if (!platformData) … … 400 403 401 404 return *addResult.iterator->value; 405 } 406 407 void FontCache::purgeTimerFired() 408 { 409 purgeInactiveFontDataIfNeeded(); 402 410 } 403 411 … … 420 428 { 421 429 pruneUnreferencedEntriesFromFontGlyphsCache(); 422 423 if (m_purgePreventCount)424 return;425 430 426 431 #if PLATFORM(IOS) -
trunk/Source/WebCore/platform/graphics/FontCache.h
r178180 r178250 32 32 33 33 #include "FontDescription.h" 34 #include "Timer.h" 34 35 #include <limits.h> 35 36 #include <wtf/Forward.h> … … 104 105 105 106 class FontCache { 106 friend class FontCachePurgePreventer;107 107 friend class WTF::NeverDestroyed<FontCache>; 108 108 … … 164 164 ~FontCache(); 165 165 166 void disablePurging() { m_purgePreventCount++; } 167 void enablePurging() 168 { 169 ASSERT(m_purgePreventCount); 170 if (!--m_purgePreventCount) 171 purgeInactiveFontDataIfNeeded(); 172 } 166 void purgeTimerFired(); 173 167 174 void WEBCORE_EXPORTpurgeInactiveFontDataIfNeeded();168 void purgeInactiveFontDataIfNeeded(); 175 169 176 170 // FIXME: This method should eventually be removed. … … 184 178 std::unique_ptr<FontPlatformData> createFontPlatformData(const FontDescription&, const AtomicString& family); 185 179 186 // Don't purge if this count is > 0; 187 int m_purgePreventCount; 180 Timer m_purgeTimer; 188 181 189 182 #if PLATFORM(COCOA) … … 196 189 WEBCORE_EXPORT FontCache& fontCache(); 197 190 198 class FontCachePurgePreventer {199 public:200 FontCachePurgePreventer() { fontCache().disablePurging(); }201 ~FontCachePurgePreventer() { fontCache().enablePurging(); }202 };203 204 191 } 205 192 -
trunk/Source/WebCore/platform/graphics/FontFastPath.cpp
r177955 r178250 25 25 26 26 #include "FloatRect.h" 27 #include "FontCache.h"28 27 #include "FontGlyphs.h" 29 28 #include "GlyphBuffer.h" … … 70 69 int Font::emphasisMarkAscent(const AtomicString& mark) const 71 70 { 72 FontCachePurgePreventer purgePreventer;73 74 71 GlyphData markGlyphData; 75 72 if (!getEmphasisMarkGlyphData(mark, markGlyphData)) … … 86 83 int Font::emphasisMarkDescent(const AtomicString& mark) const 87 84 { 88 FontCachePurgePreventer purgePreventer;89 90 85 GlyphData markGlyphData; 91 86 if (!getEmphasisMarkGlyphData(mark, markGlyphData)) … … 102 97 int Font::emphasisMarkHeight(const AtomicString& mark) const 103 98 { 104 FontCachePurgePreventer purgePreventer;105 106 99 GlyphData markGlyphData; 107 100 if (!getEmphasisMarkGlyphData(mark, markGlyphData)) … … 241 234 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRun& run, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoint& point) const 242 235 { 243 FontCachePurgePreventer purgePreventer;244 245 236 GlyphData markGlyphData; 246 237 if (!getEmphasisMarkGlyphData(mark, markGlyphData)) -
trunk/Source/WebCore/platform/graphics/ca/win/PlatformCALayerWinInternal.cpp
r175700 r178250 29 29 30 30 #include "Font.h" 31 #include "FontCache.h"32 31 #include "GraphicsContext.h" 33 32 #include "PlatformCALayer.h" … … 132 131 133 132 if (owner()->owner()->platformCALayerShowRepaintCounter(owner())) { 134 FontCachePurgePreventer fontCachePurgePreventer;135 136 133 String text = String::number(owner()->owner()->platformCALayerIncrementRepaintCount(owner())); 137 134 -
trunk/Source/WebCore/platform/mac/DragImageMac.mm
r177876 r178250 30 30 #import "BitmapImage.h" 31 31 #import "Font.h" 32 #import "FontCache.h"33 32 #import "FontDescription.h" 34 33 #import "FontSelector.h" … … 193 192 194 193 if (canUseFastRenderer(buffer.data(), length)) { 195 FontCachePurgePreventer fontCachePurgePreventer;196 197 194 Font webCoreFont(FontPlatformData(font, [font pointSize]), ![[NSGraphicsContext currentContext] isDrawingToScreen]); 198 195 TextRun run(buffer.data(), length); … … 219 216 220 217 if (canUseFastRenderer(buffer.data(), length)) { 221 FontCachePurgePreventer fontCachePurgePreventer;222 223 218 // The following is a half-assed attempt to match AppKit's rounding rules for drawAtPoint. 224 219 // It's probably incorrect for high DPI. … … 273 268 DragImageRef createDragImageForLink(URL& url, const String& title, FontRenderingMode) 274 269 { 275 FontCachePurgePreventer fontCachePurgePreventer;276 277 270 NSString *label = nsStringNilIfEmpty(title); 278 271 NSURL *cocoaURL = url; -
trunk/Source/WebCore/platform/win/DragImageWin.cpp
r173949 r178250 29 29 #include "FloatRoundedRect.h" 30 30 #include "Font.h" 31 #include "FontCache.h"32 31 #include "FontDescription.h" 33 32 #include "FontSelector.h" … … 127 126 const Font* labelFont; 128 127 const Font* urlFont; 129 FontCachePurgePreventer fontCachePurgePreventer;130 128 131 129 if (fontRenderingMode == AlternateRenderingMode) { -
trunk/Source/WebCore/platform/win/WebCoreTextRenderer.cpp
r166063 r178250 27 27 28 28 #include "Font.h" 29 #include "FontCache.h"30 29 #include "FontDescription.h" 31 30 #include "GraphicsContext.h" … … 49 48 static void doDrawTextAtPoint(GraphicsContext& context, const String& text, const IntPoint& point, const Font& font, const Color& color, int underlinedIndex) 50 49 { 51 FontCachePurgePreventer fontCachePurgePreventer;52 53 50 TextRun run(text); 54 51 … … 95 92 float WebCoreTextFloatWidth(const String& text, const Font& font) 96 93 { 97 FontCachePurgePreventer fontCachePurgePreventer;98 99 94 return StringTruncator::width(text, font, StringTruncator::EnableRoundingHacks); 100 95 } -
trunk/Source/WebCore/rendering/InlineTextBox.cpp
r177955 r178250 31 31 #include "Editor.h" 32 32 #include "EllipsisBox.h" 33 #include "FontCache.h"34 33 #include "Frame.h" 35 34 #include "GraphicsContext.h" … … 264 263 if (sPos > ePos) 265 264 return LayoutRect(); 266 267 FontCachePurgePreventer fontCachePurgePreventer;268 265 269 266 LayoutUnit selectionTop = this->selectionTop(); … … 1332 1329 return isLeftToRightDirection() ? 0 : len(); 1333 1330 1334 FontCachePurgePreventer fontCachePurgePreventer;1335 1336 1331 const RenderStyle& lineStyle = this->lineStyle(); 1337 1332 const Font& font = fontToUse(lineStyle, renderer()); … … 1346 1341 if (isLineBreak()) 1347 1342 return logicalLeft(); 1348 1349 FontCachePurgePreventer fontCachePurgePreventer;1350 1343 1351 1344 const RenderStyle& lineStyle = this->lineStyle(); -
trunk/Source/WebCore/rendering/RenderImage.cpp
r177259 r178250 193 193 // we have an alt and the user meant it (its not a text we invented) 194 194 if (!m_altText.isEmpty()) { 195 FontCachePurgePreventer fontCachePurgePreventer;196 197 195 const Font& font = style().font(); 198 196 IntSize paddedTextSize(paddingWidth + std::min(ceilf(font.width(RenderBlock::constructTextRun(this, font, m_altText, style()))), maxAltTextWidth), paddingHeight + std::min(font.fontMetrics().height(), maxAltTextHeight)); -
trunk/Source/WebCore/rendering/RenderLayerBacking.cpp
r178176 r178250 34 34 #include "Chrome.h" 35 35 #include "FilterEffectRenderer.h" 36 #include "FontCache.h"37 36 #include "FrameView.h" 38 37 #include "GraphicsContext.h" … … 2186 2185 } 2187 2186 2188 FontCachePurgePreventer fontCachePurgePreventer;2189 2190 2187 RenderLayer::PaintLayerFlags paintFlags = 0; 2191 2188 if (paintingPhase & GraphicsLayerPaintBackground) -
trunk/Source/WebCore/rendering/RenderListBox.cpp
r177259 r178250 37 37 #include "EventHandler.h" 38 38 #include "FocusController.h" 39 #include "FontCache.h"40 39 #include "Frame.h" 41 40 #include "FrameSelection.h" … … 106 105 void RenderListBox::updateFromElement() 107 106 { 108 FontCachePurgePreventer fontCachePurgePreventer;109 110 107 if (m_optionsChanged) { 111 108 const Vector<HTMLElement*>& listItems = selectElement().listItems(); … … 373 370 void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint& paintOffset, int listIndex) 374 371 { 375 FontCachePurgePreventer fontCachePurgePreventer;376 377 372 const Vector<HTMLElement*>& listItems = selectElement().listItems(); 378 373 HTMLElement* listItemElement = listItems[listIndex]; -
trunk/Source/WebCore/rendering/RenderMenuList.cpp
r177259 r178250 30 30 #include "CSSFontSelector.h" 31 31 #include "Chrome.h" 32 #include "FontCache.h"33 32 #include "Frame.h" 34 33 #include "FrameView.h" … … 210 209 const Vector<HTMLElement*>& listItems = selectElement().listItems(); 211 210 int size = listItems.size(); 212 FontCachePurgePreventer fontCachePurgePreventer;213 211 214 212 for (int i = 0; i < size; ++i) { -
trunk/Source/WebCore/rendering/RenderThemeIOS.mm
r178229 r178250 584 584 return; 585 585 586 FontCachePurgePreventer fontCachePurgePreventer;587 586 float maximumWidth = localizedDateCache().maximumWidthForDateType(dateType, font, RenderThemeMeasureTextClient(font, *renderer, style)); 588 587 -
trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp
r177955 r178250 33 33 #include "RenderMathMLOperator.h" 34 34 35 #include "FontCache.h"36 35 #include "FontSelector.h" 37 36 #include "MathMLNames.h" … … 1660 1659 void RenderMathMLOperator::updateStyle() 1661 1660 { 1662 FontCachePurgePreventer fontCachePurgePreventer;1663 1664 1661 ASSERT(firstChild()); 1665 1662 if (!firstChild()) -
trunk/Source/WebCore/rendering/svg/RenderSVGText.cpp
r177259 r178250 29 29 30 30 #include "FloatQuad.h" 31 #include "FontCache.h"32 31 #include "GraphicsContext.h" 33 32 #include "HitTestRequest.h" … … 171 170 return; 172 171 173 // Always protect the cache before clearing text positioning elements when the cache will subsequently be rebuilt.174 FontCachePurgePreventer fontCachePurgePreventer;175 176 172 // The positioning elements cache doesn't include the new 'child' yet. Clear the 177 173 // cache, as the next buildLayoutAttributesForTextRenderer() call rebuilds it. … … 296 292 // Only update the metrics cache, but not the text positioning element cache 297 293 // nor the layout attributes cached in the leaf #text renderers. 298 FontCachePurgePreventer fontCachePurgePreventer;299 294 for (RenderObject* descendant = text; descendant; descendant = descendant->nextInPreOrder(text)) { 300 295 if (is<RenderSVGInlineText>(*descendant)) … … 317 312 return; 318 313 } 319 320 // Always protect the cache before clearing text positioning elements when the cache will subsequently be rebuilt.321 FontCachePurgePreventer fontCachePurgePreventer;322 314 323 315 // The positioning elements cache depends on the size of each text renderer in the … … 545 537 546 538 Vector<SVGTextLayoutAttributes*, 2> affectedAttributes; 547 FontCachePurgePreventer fontCachePurgePreventer;548 539 subtreeChildWillBeRemoved(&child, affectedAttributes); 549 540 RenderSVGBlock::removeChild(child); -
trunk/Source/WebCore/rendering/svg/SVGInlineTextBox.cpp
r177955 r178250 23 23 #include "SVGInlineTextBox.h" 24 24 25 #include "FontCache.h"26 25 #include "Frame.h" 27 26 #include "FrameView.h" … … 114 113 ASSERT_WITH_SECURITY_IMPLICATION(startPosition < endPosition); 115 114 ASSERT(style); 116 117 FontCachePurgePreventer fontCachePurgePreventer;118 115 119 116 float scalingFactor = renderer().scalingFactor(); -
trunk/Source/WebKit/mac/Misc/WebKitNSStringExtras.mm
r168047 r178250 30 30 31 31 #import <WebCore/Font.h> 32 #import <WebCore/FontCache.h>33 32 #import <WebCore/GraphicsContext.h> 34 33 #import <WebCore/TextRun.h> … … 101 100 if (!flipped) 102 101 CGContextScaleCTM(cgContext, 1, -1); 103 104 FontCachePurgePreventer fontCachePurgePreventer;105 102 106 103 Font webCoreFont(FontPlatformData(font, [font pointSize]), ![nsContext isDrawingToScreen], fontSmoothingIsAllowed ? AutoSmoothing : Antialiased); … … 150 147 151 148 if (canUseFastRenderer(buffer.data(), length)) { 152 FontCachePurgePreventer fontCachePurgePreventer;153 154 149 Font webCoreFont(FontPlatformData(font, [font pointSize]), ![[NSGraphicsContext currentContext] isDrawingToScreen]); 155 150 TextRun run(buffer.data(), length); -
trunk/Source/WebKit/mac/Misc/WebStringTruncator.mm
r166448 r178250 31 31 #import "WebSystemInterface.h" 32 32 #import <WebCore/Font.h> 33 #import <WebCore/FontCache.h>34 33 #import <WebCore/FontPlatformData.h> 35 34 #import <WebCore/StringTruncator.h> … … 61 60 { 62 61 static NeverDestroyed<RetainPtr<NSFont>> menuFont = [NSFont menuFontOfSize:0]; 63 WebCore::FontCachePurgePreventer fontCachePurgePreventer;64 62 return WebCore::StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(menuFont.get().get())); 65 63 } … … 67 65 + (NSString *)centerTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font 68 66 { 69 WebCore::FontCachePurgePreventer fontCachePurgePreventer;70 67 return WebCore::StringTruncator::centerTruncate(string, maxWidth, fontFromNSFont(font)); 71 68 } … … 73 70 + (NSString *)rightTruncateString:(NSString *)string toWidth:(float)maxWidth withFont:(NSFont *)font 74 71 { 75 WebCore::FontCachePurgePreventer fontCachePurgePreventer;76 72 return WebCore::StringTruncator::rightTruncate(string, maxWidth, fontFromNSFont(font)); 77 73 } … … 79 75 + (float)widthOfString:(NSString *)string font:(NSFont *)font 80 76 { 81 WebCore::FontCachePurgePreventer fontCachePurgePreventer;82 77 return WebCore::StringTruncator::width(string, fontFromNSFont(font)); 83 78 } -
trunk/Source/WebKit/mac/WebView/WebHTMLView.mm
r178133 r178250 4879 4879 fontDescription.setWeight(bold ? FontWeight900 : FontWeight500); 4880 4880 fontDescription.setSpecifiedSize(pointSize); 4881 FontCachePurgePreventer purgePreventer;4882 4881 RefPtr<SimpleFontData> simpleFontData = fontCache().fontForFamily(fontDescription, familyName); 4883 4882 return [simpleFontData->platformData().nsFont() fontName]; -
trunk/Source/WebKit/win/WebKitGraphics.cpp
r176892 r178250 32 32 33 33 #include <WebCore/Font.h> 34 #include <WebCore/FontCache.h>35 34 #include <WebCore/FontDescription.h> 36 35 #include <WebCore/FontSelector.h> … … 115 114 ASSERT(buffer); 116 115 117 FontCachePurgePreventer fontCachePurgePreventer;118 119 116 String result = StringTruncator::centerTruncate(String(text, length), width, makeFont(description), StringTruncator::EnableRoundingHacks); 120 117 StringView(result).getCharactersWithUpconvert(buffer); … … 126 123 { 127 124 ASSERT(buffer); 128 129 FontCachePurgePreventer fontCachePurgePreventer;130 125 131 126 String result = StringTruncator::rightTruncate(String(text, length), width, makeFont(description), StringTruncator::EnableRoundingHacks);
Note: See TracChangeset
for help on using the changeset viewer.