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() { |
| 13 SkTDynamicHash<BitmapTextBlob, uint32_t>::Iter iter(&fCache); |
| 14 while (!iter.done()) { |
| 15 (&(*iter))->unref(); |
| 16 ++iter; |
| 17 } |
| 18 } |
| 19 |
12 GrAtlasTextContext::BitmapTextBlob* GrTextBlobCache::createBlob(int glyphCount,
int runCount, | 20 GrAtlasTextContext::BitmapTextBlob* GrTextBlobCache::createBlob(int glyphCount,
int runCount, |
13 size_t maxVASize
) { | 21 size_t maxVASize
) { |
14 // We allocate size for the BitmapTextBlob itself, plus size for the vertice
s array, | 22 // We allocate size for the BitmapTextBlob itself, plus size for the vertice
s array, |
15 // and size for the glyphIds array. | 23 // and size for the glyphIds array. |
16 size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize; | 24 size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize; |
17 size_t size = sizeof(BitmapTextBlob) + | 25 size_t size = sizeof(BitmapTextBlob) + |
18 verticesCount + | 26 verticesCount + |
19 glyphCount * sizeof(GrGlyph::PackedID) + | 27 glyphCount * sizeof(GrGlyph::PackedID) + |
20 sizeof(BitmapTextBlob::Run) * runCount; | 28 sizeof(BitmapTextBlob::Run) * runCount; |
21 | 29 |
22 BitmapTextBlob* cacheBlob = SkNEW_PLACEMENT(fPool.allocate(size), BitmapText
Blob); | 30 BitmapTextBlob* cacheBlob = SkNEW_PLACEMENT(fPool.allocate(size), BitmapText
Blob); |
23 | 31 |
24 // setup offsets for vertices / glyphs | 32 // setup offsets for vertices / glyphs |
25 cacheBlob->fVertices = sizeof(BitmapTextBlob) + reinterpret_cast<unsigned ch
ar*>(cacheBlob); | 33 cacheBlob->fVertices = sizeof(BitmapTextBlob) + reinterpret_cast<unsigned ch
ar*>(cacheBlob); |
26 cacheBlob->fGlyphIDs = | 34 cacheBlob->fGlyphIDs = |
27 reinterpret_cast<GrGlyph::PackedID*>(cacheBlob->fVertices + vertices
Count); | 35 reinterpret_cast<GrGlyph::PackedID*>(cacheBlob->fVertices + vertices
Count); |
28 cacheBlob->fRuns = reinterpret_cast<BitmapTextBlob::Run*>(cacheBlob->fGlyphI
Ds + glyphCount); | 36 cacheBlob->fRuns = reinterpret_cast<BitmapTextBlob::Run*>(cacheBlob->fGlyphI
Ds + glyphCount); |
29 | 37 |
30 // Initialize runs | 38 // Initialize runs |
31 for (int i = 0; i < runCount; i++) { | 39 for (int i = 0; i < runCount; i++) { |
32 SkNEW_PLACEMENT(&cacheBlob->fRuns[i], BitmapTextBlob::Run); | 40 SkNEW_PLACEMENT(&cacheBlob->fRuns[i], BitmapTextBlob::Run); |
33 } | 41 } |
34 cacheBlob->fRunCount = runCount; | 42 cacheBlob->fRunCount = runCount; |
35 cacheBlob->fSize = size; | |
36 cacheBlob->fPool = &fPool; | 43 cacheBlob->fPool = &fPool; |
37 return cacheBlob; | 44 return cacheBlob; |
38 } | 45 } |
OLD | NEW |