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 this->freeAll(); | 13 this->freeAll(); |
14 } | 14 } |
15 | 15 |
16 GrAtlasTextBlob* GrTextBlobCache::createBlob(int glyphCount, int runCount, | 16 GrAtlasTextBlob* GrTextBlobCache::createBlob(int glyphCount, int runCount, size_
t maxVASize) { |
17 size_t maxVASize
) { | |
18 // We allocate size for the GrAtlasTextBlob itself, plus size for the vertic
es array, | 17 // We allocate size for the GrAtlasTextBlob itself, plus size for the vertic
es array, |
19 // and size for the glyphIds array. | 18 // and size for the glyphIds array. |
20 size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize; | 19 size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize; |
21 size_t size = sizeof(GrAtlasTextBlob) + | 20 size_t size = sizeof(GrAtlasTextBlob) + |
22 verticesCount + | 21 verticesCount + |
23 glyphCount * sizeof(GrGlyph**) + | 22 glyphCount * sizeof(GrGlyph**) + |
24 sizeof(GrAtlasTextBlob::Run) * runCount; | 23 sizeof(GrAtlasTextBlob::Run) * runCount; |
25 | 24 |
26 GrAtlasTextBlob* cacheBlob = SkNEW_PLACEMENT(fPool.allocate(size), GrAtlasTe
xtBlob); | 25 void* allocation = fPool.allocate(size); |
| 26 #ifdef CACHE_SANITY_CHECK |
| 27 sk_bzero(allocation, size); |
| 28 #endif |
| 29 |
| 30 GrAtlasTextBlob* cacheBlob = SkNEW_PLACEMENT(allocation, GrAtlasTextBlob); |
| 31 #ifdef CACHE_SANITY_CHECK |
| 32 cacheBlob->fSize = size; |
| 33 #endif |
27 | 34 |
28 // setup offsets for vertices / glyphs | 35 // setup offsets for vertices / glyphs |
29 cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<unsigned c
har*>(cacheBlob); | 36 cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<unsigned c
har*>(cacheBlob); |
30 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + vert
icesCount); | 37 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + vert
icesCount); |
31 cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyph
s + glyphCount); | 38 cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyph
s + glyphCount); |
32 | 39 |
33 // Initialize runs | 40 // Initialize runs |
34 for (int i = 0; i < runCount; i++) { | 41 for (int i = 0; i < runCount; i++) { |
35 SkNEW_PLACEMENT(&cacheBlob->fRuns[i], GrAtlasTextBlob::Run); | 42 SkNEW_PLACEMENT(&cacheBlob->fRuns[i], GrAtlasTextBlob::Run); |
36 } | 43 } |
37 cacheBlob->fRunCount = runCount; | 44 cacheBlob->fRunCount = runCount; |
38 cacheBlob->fPool = &fPool; | 45 cacheBlob->fPool = &fPool; |
39 return cacheBlob; | 46 return cacheBlob; |
40 } | 47 } |
41 | 48 |
42 void GrTextBlobCache::freeAll() { | 49 void GrTextBlobCache::freeAll() { |
43 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key>::Iter iter(&fCache); | 50 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key>::Iter iter(&fCache); |
44 while (!iter.done()) { | 51 while (!iter.done()) { |
45 GrAtlasTextBlob* blob = &(*iter); | 52 GrAtlasTextBlob* blob = &(*iter); |
46 fBlobList.remove(blob); | 53 fBlobList.remove(blob); |
47 blob->unref(); | 54 blob->unref(); |
48 ++iter; | 55 ++iter; |
49 } | 56 } |
50 fCache.rewind(); | 57 fCache.rewind(); |
51 } | 58 } |
OLD | NEW |