| OLD | NEW |
| 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 "GrTextBlobCache.h" | 8 #include "GrTextBlobCache.h" |
| 9 | 9 |
| 10 static const int kVerticesPerGlyph = 4; | 10 static const int kVerticesPerGlyph = 4; |
| 11 | 11 |
| 12 GrTextBlobCache::~GrTextBlobCache() { | 12 GrTextBlobCache::~GrTextBlobCache() { |
| 13 SkTDynamicHash<BitmapTextBlob, BitmapTextBlob::Key>::Iter iter(&fCache); | 13 this->freeAll(); |
| 14 while (!iter.done()) { | |
| 15 (&(*iter))->unref(); | |
| 16 ++iter; | |
| 17 } | |
| 18 } | 14 } |
| 19 | 15 |
| 20 GrAtlasTextContext::BitmapTextBlob* GrTextBlobCache::createBlob(int glyphCount,
int runCount, | 16 GrAtlasTextContext::BitmapTextBlob* GrTextBlobCache::createBlob(int glyphCount,
int runCount, |
| 21 size_t maxVASize
) { | 17 size_t maxVASize
) { |
| 22 // We allocate size for the BitmapTextBlob itself, plus size for the vertice
s array, | 18 // We allocate size for the BitmapTextBlob itself, plus size for the vertice
s array, |
| 23 // and size for the glyphIds array. | 19 // and size for the glyphIds array. |
| 24 size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize; | 20 size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize; |
| 25 size_t size = sizeof(BitmapTextBlob) + | 21 size_t size = sizeof(BitmapTextBlob) + |
| 26 verticesCount + | 22 verticesCount + |
| 27 glyphCount * sizeof(GrGlyph::PackedID) + | 23 glyphCount * sizeof(GrGlyph::PackedID) + |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 } | 37 } |
| 42 cacheBlob->fRunCount = runCount; | 38 cacheBlob->fRunCount = runCount; |
| 43 cacheBlob->fPool = &fPool; | 39 cacheBlob->fPool = &fPool; |
| 44 | 40 |
| 45 #ifdef SK_DEBUG | 41 #ifdef SK_DEBUG |
| 46 cacheBlob->fTotalXError = 0; | 42 cacheBlob->fTotalXError = 0; |
| 47 cacheBlob->fTotalYError = 0; | 43 cacheBlob->fTotalYError = 0; |
| 48 #endif | 44 #endif |
| 49 return cacheBlob; | 45 return cacheBlob; |
| 50 } | 46 } |
| 47 |
| 48 void GrTextBlobCache::freeAll() { |
| 49 SkTDynamicHash<BitmapTextBlob, BitmapTextBlob::Key>::Iter iter(&fCache); |
| 50 while (!iter.done()) { |
| 51 (&(*iter))->unref(); |
| 52 ++iter; |
| 53 } |
| 54 fCache.rewind(); |
| 55 } |
| OLD | NEW |