| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkGlyphCache.h" | 8 #include "SkGlyphCache.h" |
| 9 #include "SkGlyphCache_Globals.h" | 9 #include "SkGlyphCache_Globals.h" |
| 10 #include "SkGraphics.h" | 10 #include "SkGraphics.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 int SkGlyphCache::countCachedGlyphs() const { | 114 int SkGlyphCache::countCachedGlyphs() const { |
| 115 return fGlyphMap.count(); | 115 return fGlyphMap.count(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 /////////////////////////////////////////////////////////////////////////////// | 118 /////////////////////////////////////////////////////////////////////////////// |
| 119 | 119 |
| 120 const SkGlyph& SkGlyphCache::getUnicharAdvance(SkUnichar charCode) { | 120 const SkGlyph& SkGlyphCache::getUnicharAdvance(SkUnichar charCode) { |
| 121 VALIDATE(); | 121 VALIDATE(); |
| 122 return *this->lookupByChar(charCode); | 122 return *this->lookupByChar(charCode, kJustAdvance_MetricsType); |
| 123 } | 123 } |
| 124 | 124 |
| 125 const SkGlyph& SkGlyphCache::getGlyphIDAdvance(uint16_t glyphID) { | 125 const SkGlyph& SkGlyphCache::getGlyphIDAdvance(uint16_t glyphID) { |
| 126 VALIDATE(); | 126 VALIDATE(); |
| 127 PackedGlyphID packedGlyphID = SkGlyph::MakeID(glyphID); | 127 PackedGlyphID packedGlyphID = SkGlyph::MakeID(glyphID); |
| 128 return *this->lookupByPackedGlyphID(packedGlyphID); | 128 return *this->lookupByPackedGlyphID(packedGlyphID, kJustAdvance_MetricsType)
; |
| 129 } | 129 } |
| 130 | 130 |
| 131 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
| 132 | 132 |
| 133 const SkGlyph& SkGlyphCache::getUnicharMetrics(SkUnichar charCode) { | 133 const SkGlyph& SkGlyphCache::getUnicharMetrics(SkUnichar charCode) { |
| 134 VALIDATE(); | 134 VALIDATE(); |
| 135 return *this->lookupByChar(charCode); | 135 return *this->lookupByChar(charCode, kFull_MetricsType); |
| 136 } | 136 } |
| 137 | 137 |
| 138 const SkGlyph& SkGlyphCache::getUnicharMetrics(SkUnichar charCode, SkFixed x, Sk
Fixed y) { | 138 const SkGlyph& SkGlyphCache::getUnicharMetrics(SkUnichar charCode, SkFixed x, Sk
Fixed y) { |
| 139 VALIDATE(); | 139 VALIDATE(); |
| 140 return *this->lookupByChar(charCode, x, y); | 140 return *this->lookupByChar(charCode, kFull_MetricsType, x, y); |
| 141 } | 141 } |
| 142 | 142 |
| 143 const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID) { | 143 const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID) { |
| 144 VALIDATE(); | 144 VALIDATE(); |
| 145 PackedGlyphID packedGlyphID = SkGlyph::MakeID(glyphID); | 145 PackedGlyphID packedGlyphID = SkGlyph::MakeID(glyphID); |
| 146 return *this->lookupByPackedGlyphID(packedGlyphID); | 146 return *this->lookupByPackedGlyphID(packedGlyphID, kFull_MetricsType); |
| 147 } | 147 } |
| 148 | 148 |
| 149 const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID, SkFixed x, SkFi
xed y) { | 149 const SkGlyph& SkGlyphCache::getGlyphIDMetrics(uint16_t glyphID, SkFixed x, SkFi
xed y) { |
| 150 VALIDATE(); | 150 VALIDATE(); |
| 151 PackedGlyphID packedGlyphID = SkGlyph::MakeID(glyphID, x, y); | 151 PackedGlyphID packedGlyphID = SkGlyph::MakeID(glyphID, x, y); |
| 152 return *this->lookupByPackedGlyphID(packedGlyphID); | 152 return *this->lookupByPackedGlyphID(packedGlyphID, kFull_MetricsType); |
| 153 } | 153 } |
| 154 | 154 |
| 155 SkGlyph* SkGlyphCache::lookupByChar(SkUnichar charCode, SkFixed x, SkFixed y) { | 155 SkGlyph* SkGlyphCache::lookupByChar(SkUnichar charCode, MetricsType type, SkFixe
d x, SkFixed y) { |
| 156 PackedUnicharID id = SkGlyph::MakeID(charCode, x, y); | 156 PackedUnicharID id = SkGlyph::MakeID(charCode, x, y); |
| 157 CharGlyphRec* rec = this->getCharGlyphRec(id); | 157 CharGlyphRec* rec = this->getCharGlyphRec(id); |
| 158 if (rec->fPackedUnicharID != id) { | 158 if (rec->fPackedUnicharID != id) { |
| 159 // this ID is based on the UniChar | 159 // this ID is based on the UniChar |
| 160 rec->fPackedUnicharID = id; | 160 rec->fPackedUnicharID = id; |
| 161 // this ID is based on the glyph index | 161 // this ID is based on the glyph index |
| 162 PackedGlyphID combinedID = SkGlyph::MakeID(fScalerContext->charToGlyphID
(charCode), x, y); | 162 PackedGlyphID combinedID = SkGlyph::MakeID(fScalerContext->charToGlyphID
(charCode), x, y); |
| 163 rec->fPackedGlyphID = combinedID; | 163 rec->fPackedGlyphID = combinedID; |
| 164 return this->lookupByPackedGlyphID(combinedID); | 164 return this->lookupByPackedGlyphID(combinedID, type); |
| 165 } else { | 165 } else { |
| 166 return this->lookupByPackedGlyphID(rec->fPackedGlyphID); | 166 return this->lookupByPackedGlyphID(rec->fPackedGlyphID, type); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 SkGlyph* SkGlyphCache::lookupByPackedGlyphID(PackedGlyphID packedGlyphID) { | 170 SkGlyph* SkGlyphCache::lookupByPackedGlyphID(PackedGlyphID packedGlyphID, Metric
sType type) { |
| 171 SkGlyph* glyph = fGlyphMap.find(packedGlyphID); | 171 SkGlyph* glyph = fGlyphMap.find(packedGlyphID); |
| 172 |
| 172 if (nullptr == glyph) { | 173 if (nullptr == glyph) { |
| 173 glyph = this->allocateNewGlyph(packedGlyphID); | 174 glyph = this->allocateNewGlyph(packedGlyphID, type); |
| 175 } else { |
| 176 if (type == kFull_MetricsType && glyph->isJustAdvance()) { |
| 177 fScalerContext->getMetrics(glyph); |
| 178 } |
| 174 } | 179 } |
| 175 return glyph; | 180 return glyph; |
| 176 } | 181 } |
| 177 | 182 |
| 178 SkGlyph* SkGlyphCache::allocateNewGlyph(PackedGlyphID packedGlyphID) { | 183 SkGlyph* SkGlyphCache::allocateNewGlyph(PackedGlyphID packedGlyphID, MetricsType
mtype) { |
| 179 fMemoryUsed += sizeof(SkGlyph); | 184 fMemoryUsed += sizeof(SkGlyph); |
| 180 | 185 |
| 181 SkGlyph* glyphPtr; | 186 SkGlyph* glyphPtr; |
| 182 { | 187 { |
| 183 SkGlyph glyph; | 188 SkGlyph glyph; |
| 184 glyph.initGlyphFromCombinedID(packedGlyphID); | 189 glyph.initGlyphFromCombinedID(packedGlyphID); |
| 185 glyphPtr = fGlyphMap.set(glyph); | 190 glyphPtr = fGlyphMap.set(glyph); |
| 186 } | 191 } |
| 187 fScalerContext->getMetrics(glyphPtr); | 192 |
| 193 if (kJustAdvance_MetricsType == mtype) { |
| 194 fScalerContext->getAdvance(glyphPtr); |
| 195 } else { |
| 196 SkASSERT(kFull_MetricsType == mtype); |
| 197 fScalerContext->getMetrics(glyphPtr); |
| 198 } |
| 188 | 199 |
| 189 SkASSERT(glyphPtr->fID != SkGlyph::kImpossibleID); | 200 SkASSERT(glyphPtr->fID != SkGlyph::kImpossibleID); |
| 190 return glyphPtr; | 201 return glyphPtr; |
| 191 } | 202 } |
| 192 | 203 |
| 193 const void* SkGlyphCache::findImage(const SkGlyph& glyph) { | 204 const void* SkGlyphCache::findImage(const SkGlyph& glyph) { |
| 194 if (glyph.fWidth > 0 && glyph.fWidth < kMaxGlyphWidth) { | 205 if (glyph.fWidth > 0 && glyph.fWidth < kMaxGlyphWidth) { |
| 195 if (nullptr == glyph.fImage) { | 206 if (nullptr == glyph.fImage) { |
| 196 size_t size = glyph.computeImageSize(); | 207 size_t size = glyph.computeImageSize(); |
| 197 const_cast<SkGlyph&>(glyph).fImage = fGlyphAlloc.alloc(size, | 208 const_cast<SkGlyph&>(glyph).fImage = fGlyphAlloc.alloc(size, |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 } | 649 } |
| 639 | 650 |
| 640 void SkGraphics::PurgeFontCache() { | 651 void SkGraphics::PurgeFontCache() { |
| 641 get_globals().purgeAll(); | 652 get_globals().purgeAll(); |
| 642 SkTypefaceCache::PurgeAll(); | 653 SkTypefaceCache::PurgeAll(); |
| 643 } | 654 } |
| 644 | 655 |
| 645 // TODO(herb): clean up TLS apis. | 656 // TODO(herb): clean up TLS apis. |
| 646 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } | 657 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } |
| 647 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } | 658 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } |
| OLD | NEW |