| 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 "platform/heap/Handle.h" |
| 31 #include "wtf/Threading.h" | 32 #include "wtf/Threading.h" |
| 32 | 33 |
| 33 namespace blink { | 34 namespace blink { |
| 34 | 35 |
| 35 CSSValuePool& cssValuePool() | 36 CSSValuePool& cssValuePool() |
| 36 { | 37 { |
| 37 DEFINE_STATIC_LOCAL(CSSValuePool, pool, (new CSSValuePool)); | 38 DEFINE_THREAD_SAFE_STATIC_LOCAL(ThreadSpecific<Persistent<CSSValuePool>>, th
readSpecificPool, new ThreadSpecific<Persistent<CSSValuePool>>()); |
| 38 return pool; | 39 Persistent<CSSValuePool>& poolHandle = *threadSpecificPool; |
| 40 if (!poolHandle) { |
| 41 poolHandle = new CSSValuePool(); |
| 42 poolHandle.clearOnThreadShutdown(); |
| 43 } |
| 44 return *poolHandle; |
| 39 } | 45 } |
| 40 | 46 |
| 41 CSSValuePool::CSSValuePool() | 47 CSSValuePool::CSSValuePool() |
| 42 : m_inheritedValue(CSSInheritedValue::create()) | 48 : m_inheritedValue(CSSInheritedValue::create()) |
| 43 , m_implicitInitialValue(CSSInitialValue::createImplicit()) | 49 , m_implicitInitialValue(CSSInitialValue::createImplicit()) |
| 44 , m_explicitInitialValue(CSSInitialValue::createExplicit()) | 50 , m_explicitInitialValue(CSSInitialValue::createExplicit()) |
| 45 , m_unsetValue(CSSUnsetValue::create()) | 51 , m_unsetValue(CSSUnsetValue::create()) |
| 46 , m_colorTransparent(CSSColorValue::create(Color::transparent)) | 52 , m_colorTransparent(CSSColorValue::create(Color::transparent)) |
| 47 , m_colorWhite(CSSColorValue::create(Color::white)) | 53 , m_colorWhite(CSSColorValue::create(Color::white)) |
| 48 , m_colorBlack(CSSColorValue::create(Color::black)) | 54 , m_colorBlack(CSSColorValue::create(Color::black)) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 72 { | 78 { |
| 73 // These are the empty and deleted values of the hash table. | 79 // These are the empty and deleted values of the hash table. |
| 74 if (rgbValue == Color::transparent) | 80 if (rgbValue == Color::transparent) |
| 75 return m_colorTransparent; | 81 return m_colorTransparent; |
| 76 if (rgbValue == Color::white) | 82 if (rgbValue == Color::white) |
| 77 return m_colorWhite; | 83 return m_colorWhite; |
| 78 // Just because it is common. | 84 // Just because it is common. |
| 79 if (rgbValue == Color::black) | 85 if (rgbValue == Color::black) |
| 80 return m_colorBlack; | 86 return m_colorBlack; |
| 81 | 87 |
| 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 | |
| 90 // Just wipe out the cache and start rebuilding if it gets too big. | 88 // Just wipe out the cache and start rebuilding if it gets too big. |
| 91 const unsigned maximumColorCacheSize = 512; | 89 const unsigned maximumColorCacheSize = 512; |
| 92 if (m_colorValueCache.size() > maximumColorCacheSize) | 90 if (m_colorValueCache.size() > maximumColorCacheSize) |
| 93 m_colorValueCache.clear(); | 91 m_colorValueCache.clear(); |
| 94 | 92 |
| 95 CSSColorValue* dummyValue = nullptr; | 93 CSSColorValue* dummyValue = nullptr; |
| 96 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); | 94 ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValu
e); |
| 97 if (entry.isNewEntry) | 95 if (entry.isNewEntry) |
| 98 entry.storedValue->value = CSSColorValue::create(rgbValue); | 96 entry.storedValue->value = CSSColorValue::create(rgbValue); |
| 99 | 97 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 visitor->trace(m_colorWhite); | 172 visitor->trace(m_colorWhite); |
| 175 visitor->trace(m_colorBlack); | 173 visitor->trace(m_colorBlack); |
| 176 visitor->trace(m_pixelValueCache); | 174 visitor->trace(m_pixelValueCache); |
| 177 visitor->trace(m_percentValueCache); | 175 visitor->trace(m_percentValueCache); |
| 178 visitor->trace(m_numberValueCache); | 176 visitor->trace(m_numberValueCache); |
| 179 visitor->trace(m_fontFaceValueCache); | 177 visitor->trace(m_fontFaceValueCache); |
| 180 visitor->trace(m_fontFamilyValueCache); | 178 visitor->trace(m_fontFamilyValueCache); |
| 181 } | 179 } |
| 182 | 180 |
| 183 } // namespace blink | 181 } // namespace blink |
| OLD | NEW |