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

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 1188663005: Speed-up font switching in CanvasRenderingContext2D by only validating uncached values (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: moved literal "initial" into const Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved.
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 #include "wtf/MathExtras.h" 72 #include "wtf/MathExtras.h"
73 #include "wtf/OwnPtr.h" 73 #include "wtf/OwnPtr.h"
74 #include "wtf/text/StringBuilder.h" 74 #include "wtf/text/StringBuilder.h"
75 75
76 namespace blink { 76 namespace blink {
77 77
78 static const int defaultFontSize = 10; 78 static const int defaultFontSize = 10;
79 static const char defaultFontFamily[] = "sans-serif"; 79 static const char defaultFontFamily[] = "sans-serif";
80 static const char defaultFont[] = "10px sans-serif"; 80 static const char defaultFont[] = "10px sans-serif";
81 static const char inherit[] = "inherit"; 81 static const char inherit[] = "inherit";
82 static const char initial[] = "initial";
82 static const char rtl[] = "rtl"; 83 static const char rtl[] = "rtl";
83 static const char ltr[] = "ltr"; 84 static const char ltr[] = "ltr";
84 static const double TryRestoreContextInterval = 0.5; 85 static const double TryRestoreContextInterval = 0.5;
85 static const unsigned MaxTryRestoreContextAttempts = 4; 86 static const unsigned MaxTryRestoreContextAttempts = 4;
86 static const unsigned FetchedFontsCacheLimit = 50; 87 static const unsigned FetchedFontsCacheLimit = 50;
87 static const float cDeviceScaleFactor = 1.0f; // Canvas is device independent 88 static const float cDeviceScaleFactor = 1.0f; // Canvas is device independent
88 89
89 static bool contextLostRestoredEventsEnabled() 90 static bool contextLostRestoredEventsEnabled()
90 { 91 {
91 return RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled(); 92 return RuntimeEnabledFeatures::experimentalCanvasFeaturesEnabled();
(...skipping 1580 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 if (i != m_fetchedFonts.end()) { 1673 if (i != m_fetchedFonts.end()) {
1673 parsedStyle = i->value; 1674 parsedStyle = i->value;
1674 m_fetchedFontsLRUList.remove(newFont); 1675 m_fetchedFontsLRUList.remove(newFont);
1675 } else { 1676 } else {
1676 parsedStyle = MutableStylePropertySet::create(); 1677 parsedStyle = MutableStylePropertySet::create();
1677 CSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, newFont, true, HTMLStandardMode, 0); 1678 CSSParser::parseValue(parsedStyle.get(), CSSPropertyFont, newFont, true, HTMLStandardMode, 0);
1678 if (m_fetchedFonts.size() >= FetchedFontsCacheLimit) { 1679 if (m_fetchedFonts.size() >= FetchedFontsCacheLimit) {
1679 m_fetchedFonts.remove(m_fetchedFontsLRUList.first()); 1680 m_fetchedFonts.remove(m_fetchedFontsLRUList.first());
1680 m_fetchedFontsLRUList.removeFirst(); 1681 m_fetchedFontsLRUList.removeFirst();
1681 } 1682 }
1683 if (parsedStyle->isEmpty())
1684 return;
1685 String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont);
1686 // According to http://lists.w3.org/Archives/Public/public-html/2009Jul/ 0947.html,
1687 // the "inherit" and "initial" values must be ignored.
1688 if (fontValue == inherit || fontValue == initial)
1689 return;
1682 m_fetchedFonts.add(newFont, parsedStyle); 1690 m_fetchedFonts.add(newFont, parsedStyle);
1683 } 1691 }
1684 m_fetchedFontsLRUList.add(newFont); 1692 m_fetchedFontsLRUList.add(newFont);
1685 1693
1686 if (parsedStyle->isEmpty())
1687 return;
1688
1689 String fontValue = parsedStyle->getPropertyValue(CSSPropertyFont);
1690
1691 // According to http://lists.w3.org/Archives/Public/public-html/2009Jul/0947 .html,
1692 // the "inherit" and "initial" values must be ignored.
1693 if (fontValue == "inherit" || fontValue == "initial")
1694 return;
1695
1696 // The parse succeeded. 1694 // The parse succeeded.
1697 String newFontSafeCopy(newFont); // Create a string copy since newFont can b e deleted inside realizeSaves. 1695 String newFontSafeCopy(newFont); // Create a string copy since newFont can b e deleted inside realizeSaves.
1698 modifiableState().setUnparsedFont(newFontSafeCopy); 1696 modifiableState().setUnparsedFont(newFontSafeCopy);
1699 1697
1700 // Map the <canvas> font into the text style. If the font uses keywords like larger/smaller, these will work 1698 // Map the <canvas> font into the text style. If the font uses keywords like larger/smaller, these will work
1701 // relative to the canvas. 1699 // relative to the canvas.
1702 RefPtr<ComputedStyle> newStyle = ComputedStyle::create(); 1700 RefPtr<ComputedStyle> newStyle = ComputedStyle::create();
1703 canvas()->document().updateLayoutTreeIfNeeded(); 1701 canvas()->document().updateLayoutTreeIfNeeded();
1704 if (const ComputedStyle* computedStyle = canvas()->ensureComputedStyle()) { 1702 if (const ComputedStyle* computedStyle = canvas()->ensureComputedStyle()) {
1705 FontDescription elementFontDescription(computedStyle->fontDescription()) ; 1703 FontDescription elementFontDescription(computedStyle->fontDescription()) ;
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2237 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage) 2235 if (imageType == CanvasRenderingContext2DState::NonOpaqueImage)
2238 return; 2236 return;
2239 if (alpha < 0xFF) 2237 if (alpha < 0xFF)
2240 return; 2238 return;
2241 } 2239 }
2242 2240
2243 canvas()->buffer()->willOverwriteCanvas(); 2241 canvas()->buffer()->willOverwriteCanvas();
2244 } 2242 }
2245 2243
2246 } // namespace blink 2244 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698