| OLD | NEW |
| 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 "core/html/canvas/CanvasFontCache.h" | 5 #include "core/html/canvas/CanvasFontCache.h" |
| 6 | 6 |
| 7 #include "core/css/parser/CSSParser.h" | 7 #include "core/css/parser/CSSParser.h" |
| 8 #include "core/css/resolver/StyleResolver.h" | 8 #include "core/css/resolver/StyleResolver.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/style/ComputedStyle.h" | 10 #include "core/style/ComputedStyle.h" |
| 11 #include "platform/fonts/FontCache.h" | 11 #include "platform/fonts/FontCache.h" |
| 12 #include "platform/wtf/PtrUtil.h" | 12 #include "platform/wtf/PtrUtil.h" |
| 13 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const unsigned CanvasFontCacheMaxFonts = 50; | 17 const unsigned CanvasFontCacheMaxFonts = 50; |
| 18 const unsigned CanvasFontCacheMaxFontsLowEnd = 5; |
| 18 const unsigned CanvasFontCacheHardMaxFonts = 250; | 19 const unsigned CanvasFontCacheHardMaxFonts = 250; |
| 20 const unsigned CanvasFontCacheHardMaxFontsLowEnd = 20; |
| 19 const unsigned CanvasFontCacheHiddenMaxFonts = 1; | 21 const unsigned CanvasFontCacheHiddenMaxFonts = 1; |
| 20 const int defaultFontSize = 10; | 22 const int defaultFontSize = 10; |
| 21 const char defaultFontFamily[] = "sans-serif"; | 23 const char defaultFontFamily[] = "sans-serif"; |
| 22 } | 24 } |
| 23 | 25 |
| 24 namespace blink { | 26 namespace blink { |
| 25 | 27 |
| 26 CanvasFontCache::CanvasFontCache(Document& document) | 28 CanvasFontCache::CanvasFontCache(Document& document) |
| 27 : document_(&document), pruning_scheduled_(false) { | 29 : document_(&document), pruning_scheduled_(false) { |
| 28 FontFamily font_family; | 30 FontFamily font_family; |
| 29 font_family.SetFamily(defaultFontFamily); | 31 font_family.SetFamily(defaultFontFamily); |
| 30 FontDescription default_font_description; | 32 FontDescription default_font_description; |
| 31 default_font_description.SetFamily(font_family); | 33 default_font_description.SetFamily(font_family); |
| 32 default_font_description.SetSpecifiedSize(defaultFontSize); | 34 default_font_description.SetSpecifiedSize(defaultFontSize); |
| 33 default_font_description.SetComputedSize(defaultFontSize); | 35 default_font_description.SetComputedSize(defaultFontSize); |
| 34 default_font_style_ = ComputedStyle::Create(); | 36 default_font_style_ = ComputedStyle::Create(); |
| 35 default_font_style_->SetFontDescription(default_font_description); | 37 default_font_style_->SetFontDescription(default_font_description); |
| 36 default_font_style_->GetFont().Update( | 38 default_font_style_->GetFont().Update( |
| 37 default_font_style_->GetFont().GetFontSelector()); | 39 default_font_style_->GetFont().GetFontSelector()); |
| 38 } | 40 } |
| 39 | 41 |
| 40 CanvasFontCache::~CanvasFontCache() { | 42 CanvasFontCache::~CanvasFontCache() { |
| 41 main_cache_purge_preventer_.reset(); | 43 main_cache_purge_preventer_.reset(); |
| 42 if (pruning_scheduled_) { | 44 if (pruning_scheduled_) { |
| 43 Platform::Current()->CurrentThread()->RemoveTaskObserver(this); | 45 Platform::Current()->CurrentThread()->RemoveTaskObserver(this); |
| 44 } | 46 } |
| 45 } | 47 } |
| 46 | 48 |
| 47 unsigned CanvasFontCache::MaxFonts() { | 49 unsigned CanvasFontCache::MaxFonts() { |
| 48 return CanvasFontCacheMaxFonts; | 50 return MemoryCoordinator::IsLowEndDevice() ? CanvasFontCacheMaxFontsLowEnd |
| 51 : CanvasFontCacheMaxFonts; |
| 49 } | 52 } |
| 50 | 53 |
| 51 unsigned CanvasFontCache::HardMaxFonts() { | 54 unsigned CanvasFontCache::HardMaxFonts() { |
| 52 return document_->hidden() ? CanvasFontCacheHiddenMaxFonts | 55 return document_->hidden() ? CanvasFontCacheHiddenMaxFonts |
| 53 : CanvasFontCacheHardMaxFonts; | 56 : (MemoryCoordinator::IsLowEndDevice() |
| 57 ? CanvasFontCacheHardMaxFontsLowEnd |
| 58 : CanvasFontCacheHardMaxFonts); |
| 54 } | 59 } |
| 55 | 60 |
| 56 bool CanvasFontCache::GetFontUsingDefaultStyle(const String& font_string, | 61 bool CanvasFontCache::GetFontUsingDefaultStyle(const String& font_string, |
| 57 Font& resolved_font) { | 62 Font& resolved_font) { |
| 58 HashMap<String, Font>::iterator i = | 63 HashMap<String, Font>::iterator i = |
| 59 fonts_resolved_using_default_style_.find(font_string); | 64 fonts_resolved_using_default_style_.find(font_string); |
| 60 if (i != fonts_resolved_using_default_style_.end()) { | 65 if (i != fonts_resolved_using_default_style_.end()) { |
| 61 DCHECK(font_lru_list_.Contains(font_string)); | 66 DCHECK(font_lru_list_.Contains(font_string)); |
| 62 font_lru_list_.erase(font_string); | 67 font_lru_list_.erase(font_string); |
| 63 font_lru_list_.insert(font_string); | 68 font_lru_list_.insert(font_string); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 font_lru_list_.clear(); | 153 font_lru_list_.clear(); |
| 149 fonts_resolved_using_default_style_.clear(); | 154 fonts_resolved_using_default_style_.clear(); |
| 150 } | 155 } |
| 151 | 156 |
| 152 DEFINE_TRACE(CanvasFontCache) { | 157 DEFINE_TRACE(CanvasFontCache) { |
| 153 visitor->Trace(fetched_fonts_); | 158 visitor->Trace(fetched_fonts_); |
| 154 visitor->Trace(document_); | 159 visitor->Trace(document_); |
| 155 } | 160 } |
| 156 | 161 |
| 157 } // namespace blink | 162 } // namespace blink |
| OLD | NEW |