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