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

Side by Side Diff: src/core/SkGlyphCache.cpp

Issue 1321243004: Stop using SkScalerContext::getAdvance() in SkGlyphCache. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comment Created 5 years, 3 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
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, kJustAdvance_MetricsType); 122 return *this->lookupByChar(charCode);
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, kJustAdvance_MetricsType) ; 128 return *this->lookupByPackedGlyphID(packedGlyphID);
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, kFull_MetricsType); 135 return *this->lookupByChar(charCode);
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, kFull_MetricsType, x, y); 140 return *this->lookupByChar(charCode, 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, kFull_MetricsType); 146 return *this->lookupByPackedGlyphID(packedGlyphID);
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, kFull_MetricsType); 152 return *this->lookupByPackedGlyphID(packedGlyphID);
153 } 153 }
154 154
155 SkGlyph* SkGlyphCache::lookupByChar(SkUnichar charCode, MetricsType type, SkFixe d x, SkFixed y) { 155 SkGlyph* SkGlyphCache::lookupByChar(SkUnichar charCode, SkFixed 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, type); 164 return this->lookupByPackedGlyphID(combinedID);
165 } else { 165 } else {
166 return this->lookupByPackedGlyphID(rec->fPackedGlyphID, type); 166 return this->lookupByPackedGlyphID(rec->fPackedGlyphID);
167 } 167 }
168 } 168 }
169 169
170 SkGlyph* SkGlyphCache::lookupByPackedGlyphID(PackedGlyphID packedGlyphID, Metric sType type) { 170 SkGlyph* SkGlyphCache::lookupByPackedGlyphID(PackedGlyphID packedGlyphID) {
171 SkGlyph* glyph = fGlyphMap.find(packedGlyphID); 171 SkGlyph* glyph = fGlyphMap.find(packedGlyphID);
172
173 if (nullptr == glyph) { 172 if (nullptr == glyph) {
174 glyph = this->allocateNewGlyph(packedGlyphID, type); 173 glyph = this->allocateNewGlyph(packedGlyphID);
175 } else {
176 if (type == kFull_MetricsType && glyph->isJustAdvance()) {
177 fScalerContext->getMetrics(glyph);
178 }
179 } 174 }
180 return glyph; 175 return glyph;
181 } 176 }
182 177
183 SkGlyph* SkGlyphCache::allocateNewGlyph(PackedGlyphID packedGlyphID, MetricsType mtype) { 178 SkGlyph* SkGlyphCache::allocateNewGlyph(PackedGlyphID packedGlyphID) {
184 fMemoryUsed += sizeof(SkGlyph); 179 fMemoryUsed += sizeof(SkGlyph);
185 180
186 SkGlyph* glyphPtr; 181 SkGlyph* glyphPtr;
187 { 182 {
188 SkGlyph glyph; 183 SkGlyph glyph;
189 glyph.initGlyphFromCombinedID(packedGlyphID); 184 glyph.initGlyphFromCombinedID(packedGlyphID);
190 glyphPtr = fGlyphMap.set(glyph); 185 glyphPtr = fGlyphMap.set(glyph);
191 } 186 }
192 187 fScalerContext->getMetrics(glyphPtr);
193 if (kJustAdvance_MetricsType == mtype) {
194 fScalerContext->getAdvance(glyphPtr);
195 } else {
196 SkASSERT(kFull_MetricsType == mtype);
197 fScalerContext->getMetrics(glyphPtr);
198 }
199 188
200 SkASSERT(glyphPtr->fID != SkGlyph::kImpossibleID); 189 SkASSERT(glyphPtr->fID != SkGlyph::kImpossibleID);
201 return glyphPtr; 190 return glyphPtr;
202 } 191 }
203 192
204 const void* SkGlyphCache::findImage(const SkGlyph& glyph) { 193 const void* SkGlyphCache::findImage(const SkGlyph& glyph) {
205 if (glyph.fWidth > 0 && glyph.fWidth < kMaxGlyphWidth) { 194 if (glyph.fWidth > 0 && glyph.fWidth < kMaxGlyphWidth) {
206 if (nullptr == glyph.fImage) { 195 if (nullptr == glyph.fImage) {
207 size_t size = glyph.computeImageSize(); 196 size_t size = glyph.computeImageSize();
208 const_cast<SkGlyph&>(glyph).fImage = fGlyphAlloc.alloc(size, 197 const_cast<SkGlyph&>(glyph).fImage = fGlyphAlloc.alloc(size,
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 638 }
650 639
651 void SkGraphics::PurgeFontCache() { 640 void SkGraphics::PurgeFontCache() {
652 get_globals().purgeAll(); 641 get_globals().purgeAll();
653 SkTypefaceCache::PurgeAll(); 642 SkTypefaceCache::PurgeAll();
654 } 643 }
655 644
656 // TODO(herb): clean up TLS apis. 645 // TODO(herb): clean up TLS apis.
657 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; } 646 size_t SkGraphics::GetTLSFontCacheLimit() { return 0; }
658 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { } 647 void SkGraphics::SetTLSFontCacheLimit(size_t bytes) { }
OLDNEW
« no previous file with comments | « src/core/SkGlyphCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698