OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "GrTextBlobCache.h" | |
9 | |
10 static const int kVerticesPerGlyph = 4; | |
11 | |
12 GrTextBlobCache::~GrTextBlobCache() { | |
13 this->freeAll(); | |
14 } | |
15 | |
16 GrAtlasTextBlob* GrTextBlobCache::createBlob(int glyphCount, int runCount, size_
t maxVASize) { | |
17 // We allocate size for the GrAtlasTextBlob itself, plus size for the vertic
es array, | |
18 // and size for the glyphIds array. | |
19 size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize; | |
20 size_t size = sizeof(GrAtlasTextBlob) + | |
21 verticesCount + | |
22 glyphCount * sizeof(GrGlyph**) + | |
23 sizeof(GrAtlasTextBlob::Run) * runCount; | |
24 | |
25 void* allocation = fPool.allocate(size); | |
26 #ifdef CACHE_SANITY_CHECK | |
27 sk_bzero(allocation, size); | |
28 #endif | |
29 | |
30 GrAtlasTextBlob* cacheBlob = new (allocation) GrAtlasTextBlob; | |
31 #ifdef CACHE_SANITY_CHECK | |
32 cacheBlob->fSize = size; | |
33 #endif | |
34 | |
35 // setup offsets for vertices / glyphs | |
36 cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<unsigned c
har*>(cacheBlob); | |
37 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + vert
icesCount); | |
38 cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyph
s + glyphCount); | |
39 | |
40 // Initialize runs | |
41 for (int i = 0; i < runCount; i++) { | |
42 new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run; | |
43 } | |
44 cacheBlob->fRunCount = runCount; | |
45 cacheBlob->fPool = &fPool; | |
46 return cacheBlob; | |
47 } | |
48 | |
49 void GrTextBlobCache::freeAll() { | |
50 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key>::Iter iter(&fCache); | |
51 while (!iter.done()) { | |
52 GrAtlasTextBlob* blob = &(*iter); | |
53 fBlobList.remove(blob); | |
54 blob->unref(); | |
55 ++iter; | |
56 } | |
57 fCache.rewind(); | |
58 } | |
OLD | NEW |