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

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: build warnings 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
« no previous file with comments | « src/gpu/text/GrTextBlobCache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
11
12 GrTextBlobCache::~GrTextBlobCache() { 10 GrTextBlobCache::~GrTextBlobCache() {
13 this->freeAll(); 11 this->freeAll();
14 } 12 }
15 13
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() { 14 void GrTextBlobCache::freeAll() {
48 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key>::Iter iter(&fCache); 15 SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key>::Iter iter(&fCache);
49 while (!iter.done()) { 16 while (!iter.done()) {
50 GrAtlasTextBlob* blob = &(*iter); 17 GrAtlasTextBlob* blob = &(*iter);
51 fBlobList.remove(blob); 18 fBlobList.remove(blob);
52 blob->unref(); 19 blob->unref();
53 ++iter; 20 ++iter;
54 } 21 }
55 fCache.rewind(); 22 fCache.rewind();
56 23
57 // There should be no allocations in the memory pool at this point 24 // There should be no allocations in the memory pool at this point
58 SkASSERT(fPool.isEmpty()); 25 SkASSERT(fPool.isEmpty());
59 } 26 }
OLDNEW
« no previous file with comments | « src/gpu/text/GrTextBlobCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698