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

Side by Side Diff: src/gpu/text/GrTextBlobCache.cpp

Issue 1686113002: Remove GrTextBlobCache/GrAtlasTextBlob friendliness (Closed) Base URL: https://skia.googlesource.com/skia.git@tc-cleanup-1
Patch Set: Created 4 years, 10 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
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 "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, 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 if (CACHE_SANITY_CHECK) {
27 sk_bzero(allocation, size);
28 }
29
30 GrAtlasTextBlob* cacheBlob = new (allocation) GrAtlasTextBlob;
31 cacheBlob->fSize = size;
32
33 // setup offsets for vertices / glyphs
34 cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<unsigned c har*>(cacheBlob);
35 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + vert icesCount);
36 cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyph s + glyphCount);
37
38 // Initialize runs
39 for (int i = 0; i < runCount; i++) {
40 new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run;
41 }
42 cacheBlob->fRunCount = runCount;
43 cacheBlob->fPool = &fPool;
44 return cacheBlob;
45 }
46
47 void GrTextBlobCache::freeAll() { 16 void GrTextBlobCache::freeAll() {
48 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key>::Iter iter(&fCache); 17 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key>::Iter iter(&fCache);
49 while (!iter.done()) { 18 while (!iter.done()) {
50 GrAtlasTextBlob* blob = &(*iter); 19 GrAtlasTextBlob* blob = &(*iter);
51 fBlobList.remove(blob); 20 fBlobList.remove(blob);
52 blob->unref(); 21 blob->unref();
53 ++iter; 22 ++iter;
54 } 23 }
55 fCache.rewind(); 24 fCache.rewind();
56 25
57 // There should be no allocations in the memory pool at this point 26 // There should be no allocations in the memory pool at this point
58 SkASSERT(fPool.isEmpty()); 27 SkASSERT(fPool.isEmpty());
59 } 28 }
OLDNEW
« src/gpu/text/GrTextBlobCache.h ('K') | « src/gpu/text/GrTextBlobCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698