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

Side by Side Diff: third_party/WebKit/Source/platform/fonts/FontCache.cpp

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "platform/fonts/FontSmoothingMode.h" 43 #include "platform/fonts/FontSmoothingMode.h"
44 #include "platform/fonts/SimpleFontData.h" 44 #include "platform/fonts/SimpleFontData.h"
45 #include "platform/fonts/TextRenderingMode.h" 45 #include "platform/fonts/TextRenderingMode.h"
46 #include "platform/fonts/opentype/OpenTypeVerticalData.h" 46 #include "platform/fonts/opentype/OpenTypeVerticalData.h"
47 #include "platform/fonts/shaping/ShapeCache.h" 47 #include "platform/fonts/shaping/ShapeCache.h"
48 #include "platform/web_memory_allocator_dump.h" 48 #include "platform/web_memory_allocator_dump.h"
49 #include "platform/web_process_memory_dump.h" 49 #include "platform/web_process_memory_dump.h"
50 #include "public/platform/Platform.h" 50 #include "public/platform/Platform.h"
51 #include "wtf/HashMap.h" 51 #include "wtf/HashMap.h"
52 #include "wtf/ListHashSet.h" 52 #include "wtf/ListHashSet.h"
53 #include "wtf/PtrUtil.h"
53 #include "wtf/StdLibExtras.h" 54 #include "wtf/StdLibExtras.h"
54 #include "wtf/Vector.h" 55 #include "wtf/Vector.h"
55 #include "wtf/text/AtomicStringHash.h" 56 #include "wtf/text/AtomicStringHash.h"
56 #include "wtf/text/StringHash.h" 57 #include "wtf/text/StringHash.h"
58 #include <memory>
57 59
58 using namespace WTF; 60 using namespace WTF;
59 61
60 namespace blink { 62 namespace blink {
61 63
62 #if !OS(WIN) && !OS(LINUX) 64 #if !OS(WIN) && !OS(LINUX)
63 FontCache::FontCache() 65 FontCache::FontCache()
64 : m_purgePreventCount(0) 66 : m_purgePreventCount(0)
65 , m_fontManager(nullptr) 67 , m_fontManager(nullptr)
66 { 68 {
67 } 69 }
68 #endif // !OS(WIN) && !OS(LINUX) 70 #endif // !OS(WIN) && !OS(LINUX)
69 71
70 typedef HashMap<unsigned, OwnPtr<FontPlatformData>, WTF::IntHash<unsigned>, WTF: :UnsignedWithZeroKeyHashTraits<unsigned>> SizedFontPlatformDataSet; 72 typedef HashMap<unsigned, std::unique_ptr<FontPlatformData>, WTF::IntHash<unsign ed>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> SizedFontPlatformDataSet;
71 typedef HashMap<FontCacheKey, SizedFontPlatformDataSet, FontCacheKeyHash, FontCa cheKeyTraits> FontPlatformDataCache; 73 typedef HashMap<FontCacheKey, SizedFontPlatformDataSet, FontCacheKeyHash, FontCa cheKeyTraits> FontPlatformDataCache;
72 typedef HashMap<FallbackListCompositeKey, OwnPtr<ShapeCache>, FallbackListCompos iteKeyHash, FallbackListCompositeKeyTraits> FallbackListShaperCache; 74 typedef HashMap<FallbackListCompositeKey, std::unique_ptr<ShapeCache>, FallbackL istCompositeKeyHash, FallbackListCompositeKeyTraits> FallbackListShaperCache;
73 75
74 static FontPlatformDataCache* gFontPlatformDataCache = nullptr; 76 static FontPlatformDataCache* gFontPlatformDataCache = nullptr;
75 static FallbackListShaperCache* gFallbackListShaperCache = nullptr; 77 static FallbackListShaperCache* gFallbackListShaperCache = nullptr;
76 78
77 SkFontMgr* FontCache::s_fontManager = nullptr; 79 SkFontMgr* FontCache::s_fontManager = nullptr;
78 80
79 #if OS(WIN) 81 #if OS(WIN)
80 bool FontCache::s_antialiasedTextEnabled = false; 82 bool FontCache::s_antialiasedTextEnabled = false;
81 bool FontCache::s_lcdTextEnabled = false; 83 bool FontCache::s_lcdTextEnabled = false;
82 float FontCache::s_deviceScaleFactor = 1.0; 84 float FontCache::s_deviceScaleFactor = 1.0;
(...skipping 28 matching lines...) Expand all
111 113
112 { 114 {
113 // addResult's scope must end before we recurse for alternate family nam es below, 115 // addResult's scope must end before we recurse for alternate family nam es below,
114 // to avoid trigering its dtor hash-changed asserts. 116 // to avoid trigering its dtor hash-changed asserts.
115 SizedFontPlatformDataSet* sizedFonts = &gFontPlatformDataCache->add(key, SizedFontPlatformDataSet()).storedValue->value; 117 SizedFontPlatformDataSet* sizedFonts = &gFontPlatformDataCache->add(key, SizedFontPlatformDataSet()).storedValue->value;
116 bool wasEmpty = sizedFonts->isEmpty(); 118 bool wasEmpty = sizedFonts->isEmpty();
117 119
118 // Take a different size instance of the same font before adding an entr y to |sizedFont|. 120 // Take a different size instance of the same font before adding an entr y to |sizedFont|.
119 FontPlatformData* anotherSize = wasEmpty ? nullptr : sizedFonts->begin() ->value.get(); 121 FontPlatformData* anotherSize = wasEmpty ? nullptr : sizedFonts->begin() ->value.get();
120 auto addResult = sizedFonts->add(roundedSize, nullptr); 122 auto addResult = sizedFonts->add(roundedSize, nullptr);
121 OwnPtr<FontPlatformData>* found = &addResult.storedValue->value; 123 std::unique_ptr<FontPlatformData>* found = &addResult.storedValue->value ;
122 if (addResult.isNewEntry) { 124 if (addResult.isNewEntry) {
123 if (wasEmpty) 125 if (wasEmpty)
124 *found = createFontPlatformData(fontDescription, creationParams, size); 126 *found = createFontPlatformData(fontDescription, creationParams, size);
125 else if (anotherSize) 127 else if (anotherSize)
126 *found = scaleFontPlatformData(*anotherSize, fontDescription, cr eationParams, size); 128 *found = scaleFontPlatformData(*anotherSize, fontDescription, cr eationParams, size);
127 } 129 }
128 130
129 result = found->get(); 131 result = found->get();
130 foundResult = result || !addResult.isNewEntry; 132 foundResult = result || !addResult.isNewEntry;
131 } 133 }
132 134
133 if (!foundResult && !checkingAlternateName && creationParams.creationType() == CreateFontByFamily) { 135 if (!foundResult && !checkingAlternateName && creationParams.creationType() == CreateFontByFamily) {
134 // We were unable to find a font. We have a small set of fonts that we a lias to other names, 136 // We were unable to find a font. We have a small set of fonts that we a lias to other names,
135 // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the f ont under the aliased name. 137 // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the f ont under the aliased name.
136 const AtomicString& alternateName = alternateFamilyName(creationParams.f amily()); 138 const AtomicString& alternateName = alternateFamilyName(creationParams.f amily());
137 if (!alternateName.isEmpty()) { 139 if (!alternateName.isEmpty()) {
138 FontFaceCreationParams createByAlternateFamily(alternateName); 140 FontFaceCreationParams createByAlternateFamily(alternateName);
139 result = getFontPlatformData(fontDescription, createByAlternateFamil y, true); 141 result = getFontPlatformData(fontDescription, createByAlternateFamil y, true);
140 } 142 }
141 if (result) { 143 if (result) {
142 // Cache the result under the old name. 144 // Cache the result under the old name.
143 auto adding = &gFontPlatformDataCache->add(key, SizedFontPlatformDat aSet()).storedValue->value; 145 auto adding = &gFontPlatformDataCache->add(key, SizedFontPlatformDat aSet()).storedValue->value;
144 adding->set(roundedSize, adoptPtr(new FontPlatformData(*result))); 146 adding->set(roundedSize, wrapUnique(new FontPlatformData(*result)));
145 } 147 }
146 } 148 }
147 149
148 return result; 150 return result;
149 } 151 }
150 152
151 PassOwnPtr<FontPlatformData> FontCache::scaleFontPlatformData(const FontPlatform Data& fontPlatformData, const FontDescription& fontDescription, const FontFaceCr eationParams& creationParams, float fontSize) 153 std::unique_ptr<FontPlatformData> FontCache::scaleFontPlatformData(const FontPla tformData& fontPlatformData, const FontDescription& fontDescription, const FontF aceCreationParams& creationParams, float fontSize)
152 { 154 {
153 #if OS(MACOSX) 155 #if OS(MACOSX)
154 return createFontPlatformData(fontDescription, creationParams, fontSize); 156 return createFontPlatformData(fontDescription, creationParams, fontSize);
155 #else 157 #else
156 return adoptPtr(new FontPlatformData(fontPlatformData, fontSize)); 158 return wrapUnique(new FontPlatformData(fontPlatformData, fontSize));
157 #endif 159 #endif
158 } 160 }
159 161
160 ShapeCache* FontCache::getShapeCache(const FallbackListCompositeKey& key) 162 ShapeCache* FontCache::getShapeCache(const FallbackListCompositeKey& key)
161 { 163 {
162 if (!gFallbackListShaperCache) 164 if (!gFallbackListShaperCache)
163 gFallbackListShaperCache = new FallbackListShaperCache; 165 gFallbackListShaperCache = new FallbackListShaperCache;
164 166
165 FallbackListShaperCache::iterator it = gFallbackListShaperCache->find(key); 167 FallbackListShaperCache::iterator it = gFallbackListShaperCache->find(key);
166 ShapeCache* result = nullptr; 168 ShapeCache* result = nullptr;
167 if (it == gFallbackListShaperCache->end()) { 169 if (it == gFallbackListShaperCache->end()) {
168 result = new ShapeCache(); 170 result = new ShapeCache();
169 gFallbackListShaperCache->set(key, adoptPtr(result)); 171 gFallbackListShaperCache->set(key, wrapUnique(result));
170 } else { 172 } else {
171 result = it->value.get(); 173 result = it->value.get();
172 } 174 }
173 175
174 ASSERT(result); 176 ASSERT(result);
175 return result; 177 return result;
176 } 178 }
177 179
178 typedef HashMap<FontCache::FontFileKey, RefPtr<OpenTypeVerticalData>, IntHash<Fo ntCache::FontFileKey>, UnsignedWithZeroKeyHashTraits<FontCache::FontFileKey>> Fo ntVerticalDataCache; 180 typedef HashMap<FontCache::FontFileKey, RefPtr<OpenTypeVerticalData>, IntHash<Fo ntCache::FontFileKey>, UnsignedWithZeroKeyHashTraits<FontCache::FontFileKey>> Fo ntVerticalDataCache;
179 181
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 case USCRIPT_SIMPLIFIED_HAN: 422 case USCRIPT_SIMPLIFIED_HAN:
421 return "zh-Hans"; 423 return "zh-Hans";
422 case USCRIPT_TRADITIONAL_HAN: 424 case USCRIPT_TRADITIONAL_HAN:
423 return "zh-Hant"; 425 return "zh-Hant";
424 default: 426 default:
425 return locale.ascii(); 427 return locale.ascii();
426 } 428 }
427 } 429 }
428 430
429 } // namespace blink 431 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698