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

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

Issue 1087203004: Store pointers to GrGlyph directly in BitmapTextBlob (Closed) Base URL: https://skia.googlesource.com/skia.git@atdfopt2
Patch Set: adding comment Created 5 years, 8 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/GrBatchFontCache.cpp ('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; 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 GrAtlasTextContext::BitmapTextBlob* GrTextBlobCache::createBlob(int glyphCount, int runCount, 16 GrAtlasTextContext::BitmapTextBlob* GrTextBlobCache::createBlob(int glyphCount, int runCount,
17 size_t maxVASize ) { 17 size_t maxVASize ) {
18 // We allocate size for the BitmapTextBlob itself, plus size for the vertice s array, 18 // We allocate size for the BitmapTextBlob itself, plus size for the vertice s array,
19 // and size for the glyphIds array. 19 // and size for the glyphIds array.
20 size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize; 20 size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize;
21 size_t size = sizeof(BitmapTextBlob) + 21 size_t size = sizeof(BitmapTextBlob) +
22 verticesCount + 22 verticesCount +
23 glyphCount * sizeof(GrGlyph::PackedID) + 23 glyphCount * sizeof(GrGlyph**) +
24 sizeof(BitmapTextBlob::Run) * runCount; 24 sizeof(BitmapTextBlob::Run) * runCount;
25 25
26 BitmapTextBlob* cacheBlob = SkNEW_PLACEMENT(fPool.allocate(size), BitmapText Blob); 26 BitmapTextBlob* cacheBlob = SkNEW_PLACEMENT(fPool.allocate(size), BitmapText Blob);
27 27
28 // setup offsets for vertices / glyphs 28 // setup offsets for vertices / glyphs
29 cacheBlob->fVertices = sizeof(BitmapTextBlob) + reinterpret_cast<unsigned ch ar*>(cacheBlob); 29 cacheBlob->fVertices = sizeof(BitmapTextBlob) + reinterpret_cast<unsigned ch ar*>(cacheBlob);
30 cacheBlob->fGlyphIDs = 30 cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + vert icesCount);
31 reinterpret_cast<GrGlyph::PackedID*>(cacheBlob->fVertices + vertices Count); 31 cacheBlob->fRuns = reinterpret_cast<BitmapTextBlob::Run*>(cacheBlob->fGlyphs + glyphCount);
32 cacheBlob->fRuns = reinterpret_cast<BitmapTextBlob::Run*>(cacheBlob->fGlyphI Ds + glyphCount);
33 32
34 // Initialize runs 33 // Initialize runs
35 for (int i = 0; i < runCount; i++) { 34 for (int i = 0; i < runCount; i++) {
36 SkNEW_PLACEMENT(&cacheBlob->fRuns[i], BitmapTextBlob::Run); 35 SkNEW_PLACEMENT(&cacheBlob->fRuns[i], BitmapTextBlob::Run);
37 } 36 }
38 cacheBlob->fRunCount = runCount; 37 cacheBlob->fRunCount = runCount;
39 cacheBlob->fPool = &fPool; 38 cacheBlob->fPool = &fPool;
40 39
41 #ifdef SK_DEBUG 40 #ifdef SK_DEBUG
42 cacheBlob->fTotalXError = 0; 41 cacheBlob->fTotalXError = 0;
43 cacheBlob->fTotalYError = 0; 42 cacheBlob->fTotalYError = 0;
44 #endif 43 #endif
45 return cacheBlob; 44 return cacheBlob;
46 } 45 }
47 46
48 void GrTextBlobCache::freeAll() { 47 void GrTextBlobCache::freeAll() {
49 SkTDynamicHash<BitmapTextBlob, BitmapTextBlob::Key>::Iter iter(&fCache); 48 SkTDynamicHash<BitmapTextBlob, BitmapTextBlob::Key>::Iter iter(&fCache);
50 while (!iter.done()) { 49 while (!iter.done()) {
51 (&(*iter))->unref(); 50 (&(*iter))->unref();
52 ++iter; 51 ++iter;
53 } 52 }
54 fCache.rewind(); 53 fCache.rewind();
55 } 54 }
OLDNEW
« no previous file with comments | « src/gpu/GrBatchFontCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698