| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | 23 * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "core/css/CSSValuePool.h" | 26 #include "core/css/CSSValuePool.h" |
| 27 | 27 |
| 28 #include "core/css/CSSValueList.h" | 28 #include "core/css/CSSValueList.h" |
| 29 #include "core/css/parser/CSSParser.h" | 29 #include "core/css/parser/CSSParser.h" |
| 30 #include "core/style/ComputedStyle.h" | 30 #include "core/style/ComputedStyle.h" |
| 31 #include "wtf/Threading.h" |
| 31 | 32 |
| 32 namespace blink { | 33 namespace blink { |
| 33 | 34 |
| 34 CSSValuePool& cssValuePool() | 35 CSSValuePool& cssValuePool() |
| 35 { | 36 { |
| 36 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CSSValuePool>, pool, (adoptPtrWil
lBeNoop(new CSSValuePool()))); | 37 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<CSSValuePool>, pool, (adoptPtrWil
lBeNoop(new CSSValuePool()))); |
| 37 return *pool; | 38 return *pool; |
| 38 } | 39 } |
| 39 | 40 |
| 40 CSSValuePool::CSSValuePool() | 41 CSSValuePool::CSSValuePool() |
| (...skipping 30 matching lines...) Expand all Loading... |
| 71 { | 72 { |
| 72 // These are the empty and deleted values of the hash table. | 73 // These are the empty and deleted values of the hash table. |
| 73 if (rgbValue == Color::transparent) | 74 if (rgbValue == Color::transparent) |
| 74 return m_colorTransparent; | 75 return m_colorTransparent; |
| 75 if (rgbValue == Color::white) | 76 if (rgbValue == Color::white) |
| 76 return m_colorWhite; | 77 return m_colorWhite; |
| 77 // Just because it is common. | 78 // Just because it is common. |
| 78 if (rgbValue == Color::black) | 79 if (rgbValue == Color::black) |
| 79 return m_colorBlack; | 80 return m_colorBlack; |
| 80 | 81 |
| 82 if (!isMainThread()) { |
| 83 // TODO (crbug.com/599659): Make CSS color parsing work properly in a |
| 84 // worker thread. |
| 85 // Currently, ColorValueCache is not thread-safe; so we avoid interactin
g |
| 86 // with it on a non-main thread. |
| 87 return CSSColorValue::create(rgbValue); |
| 88 } |
| 89 |
| 81 // Just wipe out the cache and start rebuilding if it gets too big. | 90 // Just wipe out the cache and start rebuilding if it gets too big. |
| 82 const unsigned maximumColorCacheSize = 512; | 91 const unsigned maximumColorCacheSize = 512; |
| 83 if (m_colorValueCache.size() > maximumColorCacheSize) | 92 if (m_colorValueCache.size() > maximumColorCacheSize) |
| 84 m_colorValueCache.clear(); | 93 m_colorValueCache.clear(); |
| 85 | 94 |
| 86 RefPtrWillBeRawPtr<CSSColorValue> dummyValue = nullptr; | 95 RefPtrWillBeRawPtr<CSSColorValue> dummyValue = nullptr; |
| 87 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); | 96 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); |
| 88 if (entry.isNewEntry) | 97 if (entry.isNewEntry) |
| 89 entry.storedValue->value = CSSColorValue::create(rgbValue); | 98 entry.storedValue->value = CSSColorValue::create(rgbValue); |
| 99 |
| 90 return entry.storedValue->value; | 100 return entry.storedValue->value; |
| 91 } | 101 } |
| 92 | 102 |
| 93 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value
, CSSPrimitiveValue::UnitType type) | 103 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value
, CSSPrimitiveValue::UnitType type) |
| 94 { | 104 { |
| 95 if (std::isinf(value)) | 105 if (std::isinf(value)) |
| 96 value = 0; | 106 value = 0; |
| 97 | 107 |
| 98 if (value < 0 || value > maximumCacheableIntegerValue) | 108 if (value < 0 || value > maximumCacheableIntegerValue) |
| 99 return CSSPrimitiveValue::create(value, type); | 109 return CSSPrimitiveValue::create(value, type); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 visitor->trace(m_colorBlack); | 176 visitor->trace(m_colorBlack); |
| 167 visitor->trace(m_pixelValueCache); | 177 visitor->trace(m_pixelValueCache); |
| 168 visitor->trace(m_percentValueCache); | 178 visitor->trace(m_percentValueCache); |
| 169 visitor->trace(m_numberValueCache); | 179 visitor->trace(m_numberValueCache); |
| 170 visitor->trace(m_fontFaceValueCache); | 180 visitor->trace(m_fontFaceValueCache); |
| 171 visitor->trace(m_fontFamilyValueCache); | 181 visitor->trace(m_fontFamilyValueCache); |
| 172 #endif | 182 #endif |
| 173 } | 183 } |
| 174 | 184 |
| 175 } // namespace blink | 185 } // namespace blink |
| OLD | NEW |