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

Side by Side Diff: src/gpu/GrBatchFontCache.cpp

Issue 1275393003: Fix for 510931, merge to m44 (Closed) Base URL: https://skia.googlesource.com/skia.git@m44
Patch Set: Created 5 years, 4 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/gpu/GrBatchFontCache.h ('k') | src/gpu/GrFontScaler.h » ('j') | 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 2015 Google Inc. 2 * Copyright 2015 Google Inc.
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 "GrBatchFontCache.h" 8 #include "GrBatchFontCache.h"
9 #include "GrFontAtlasSizes.h" 9 #include "GrFontAtlasSizes.h"
10 #include "GrGpu.h" 10 #include "GrGpu.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 166 }
167 167
168 GrBatchTextStrike::~GrBatchTextStrike() { 168 GrBatchTextStrike::~GrBatchTextStrike() {
169 SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache); 169 SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache);
170 while (!iter.done()) { 170 while (!iter.done()) {
171 (*iter).free(); 171 (*iter).free();
172 ++iter; 172 ++iter;
173 } 173 }
174 } 174 }
175 175
176 GrGlyph* GrBatchTextStrike::generateGlyph(GrGlyph::PackedID packed, 176 GrGlyph* GrBatchTextStrike::generateGlyph(const SkGlyph& skGlyph, GrGlyph::Packe dID packed,
177 GrFontScaler* scaler) { 177 GrFontScaler* scaler) {
178 SkIRect bounds; 178 SkIRect bounds;
179 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(packed)) { 179 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(packed)) {
180 if (!scaler->getPackedGlyphDFBounds(packed, &bounds)) { 180 if (!scaler->getPackedGlyphDFBounds(skGlyph, &bounds)) {
181 return NULL; 181 return NULL;
182 } 182 }
183 } else { 183 } else {
184 if (!scaler->getPackedGlyphBounds(packed, &bounds)) { 184 if (!scaler->getPackedGlyphBounds(skGlyph, &bounds)) {
185 return NULL; 185 return NULL;
186 } 186 }
187 } 187 }
188 GrMaskFormat format = scaler->getPackedGlyphMaskFormat(packed); 188 GrMaskFormat format = scaler->getPackedGlyphMaskFormat(skGlyph);
189 189
190 GrGlyph* glyph = (GrGlyph*)fPool.alloc(sizeof(GrGlyph), SK_MALLOC_THROW); 190 GrGlyph* glyph = (GrGlyph*)fPool.alloc(sizeof(GrGlyph), SK_MALLOC_THROW);
191 glyph->init(packed, bounds, format); 191 glyph->init(packed, bounds, format);
192 fCache.add(glyph); 192 fCache.add(glyph);
193 return glyph; 193 return glyph;
194 } 194 }
195 195
196 void GrBatchTextStrike::removeID(GrBatchAtlas::AtlasID id) { 196 void GrBatchTextStrike::removeID(GrBatchAtlas::AtlasID id) {
197 SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache); 197 SkTDynamicHash<GrGlyph, GrGlyph::PackedID>::Iter iter(&fCache);
198 while (!iter.done()) { 198 while (!iter.done()) {
199 if (id == (*iter).fID) { 199 if (id == (*iter).fID) {
200 (*iter).fID = GrBatchAtlas::kInvalidAtlasID; 200 (*iter).fID = GrBatchAtlas::kInvalidAtlasID;
201 fAtlasedGlyphs--; 201 fAtlasedGlyphs--;
202 SkASSERT(fAtlasedGlyphs >= 0); 202 SkASSERT(fAtlasedGlyphs >= 0);
203 } 203 }
204 ++iter; 204 ++iter;
205 } 205 }
206 } 206 }
207 207
208 bool GrBatchTextStrike::addGlyphToAtlas(GrBatchTarget* batchTarget, GrGlyph* gly ph, 208 bool GrBatchTextStrike::addGlyphToAtlas(GrBatchTarget* batchTarget, GrGlyph* gly ph,
209 GrFontScaler* scaler) { 209 GrFontScaler* scaler, const SkGlyph& skG lyph,
210 GrMaskFormat expectedMaskFormat) {
210 SkASSERT(glyph); 211 SkASSERT(glyph);
211 SkASSERT(scaler); 212 SkASSERT(scaler);
212 SkASSERT(fCache.find(glyph->fPackedID)); 213 SkASSERT(fCache.find(glyph->fPackedID));
213 SkASSERT(NULL == glyph->fPlot); 214 SkASSERT(NULL == glyph->fPlot);
214 215
215 SkAutoUnref ar(SkSafeRef(scaler)); 216 SkAutoUnref ar(SkSafeRef(scaler));
216 217
217 int bytesPerPixel = GrMaskFormatBytesPerPixel(glyph->fMaskFormat); 218 int bytesPerPixel = GrMaskFormatBytesPerPixel(expectedMaskFormat);
218 219
219 size_t size = glyph->fBounds.area() * bytesPerPixel; 220 size_t size = glyph->fBounds.area() * bytesPerPixel;
220 GrAutoMalloc<1024> storage(size); 221 GrAutoMalloc<1024> storage(size);
221 222
222 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedI D)) { 223 if (GrGlyph::kDistance_MaskStyle == GrGlyph::UnpackMaskStyle(glyph->fPackedI D)) {
223 if (!scaler->getPackedGlyphDFImage(glyph->fPackedID, glyph->width(), 224 if (!scaler->getPackedGlyphDFImage(skGlyph, glyph->width(), glyph->heigh t(),
224 glyph->height(),
225 storage.get())) { 225 storage.get())) {
226 return false; 226 return false;
227 } 227 }
228 } else { 228 } else {
229 if (!scaler->getPackedGlyphImage(glyph->fPackedID, glyph->width(), 229 if (!scaler->getPackedGlyphImage(skGlyph, glyph->width(), glyph->height( ),
230 glyph->height(), 230 glyph->width() * bytesPerPixel, expecte dMaskFormat,
231 glyph->width() * bytesPerPixel,
232 storage.get())) { 231 storage.get())) {
233 return false; 232 return false;
234 } 233 }
235 } 234 }
236 235
237 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, g lyph->fMaskFormat, 236 bool success = fBatchFontCache->addToAtlas(this, &glyph->fID, batchTarget, e xpectedMaskFormat,
238 glyph->width(), glyph->height(), 237 glyph->width(), glyph->height(),
239 storage.get(), &glyph->fAtlasLoca tion); 238 storage.get(), &glyph->fAtlasLoca tion);
240 if (success) { 239 if (success) {
241 fAtlasedGlyphs++; 240 fAtlasedGlyphs++;
242 } 241 }
243 return success; 242 return success;
244 } 243 }
OLDNEW
« no previous file with comments | « src/gpu/GrBatchFontCache.h ('k') | src/gpu/GrFontScaler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698