diff options
author | 2015-12-11 06:11:21 -0800 | |
---|---|---|
committer | 2015-12-11 06:11:21 -0800 | |
commit | e804292e805917002cc3d7baa7f967fb20d2c7cb (patch) | |
tree | 5470bacbebdec462e03929dd07d1955249b31230 /src/gpu/text/GrTextBlobCache.cpp | |
parent | 296779832fd6175547d991ca67c735a824cadb66 (diff) |
Move all text stuff to its own folder
BUG=skia:
Review URL: https://codereview.chromium.org/1521453002
Diffstat (limited to 'src/gpu/text/GrTextBlobCache.cpp')
-rw-r--r-- | src/gpu/text/GrTextBlobCache.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp new file mode 100644 index 0000000000..f11b7c60cb --- /dev/null +++ b/src/gpu/text/GrTextBlobCache.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrTextBlobCache.h" + +static const int kVerticesPerGlyph = 4; + +GrTextBlobCache::~GrTextBlobCache() { + this->freeAll(); +} + +GrAtlasTextBlob* GrTextBlobCache::createBlob(int glyphCount, int runCount, size_t maxVASize) { + // We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array, + // and size for the glyphIds array. + size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize; + size_t size = sizeof(GrAtlasTextBlob) + + verticesCount + + glyphCount * sizeof(GrGlyph**) + + sizeof(GrAtlasTextBlob::Run) * runCount; + + void* allocation = fPool.allocate(size); +#ifdef CACHE_SANITY_CHECK + sk_bzero(allocation, size); +#endif + + GrAtlasTextBlob* cacheBlob = new (allocation) GrAtlasTextBlob; +#ifdef CACHE_SANITY_CHECK + cacheBlob->fSize = size; +#endif + + // setup offsets for vertices / glyphs + cacheBlob->fVertices = sizeof(GrAtlasTextBlob) + reinterpret_cast<unsigned char*>(cacheBlob); + cacheBlob->fGlyphs = reinterpret_cast<GrGlyph**>(cacheBlob->fVertices + verticesCount); + cacheBlob->fRuns = reinterpret_cast<GrAtlasTextBlob::Run*>(cacheBlob->fGlyphs + glyphCount); + + // Initialize runs + for (int i = 0; i < runCount; i++) { + new (&cacheBlob->fRuns[i]) GrAtlasTextBlob::Run; + } + cacheBlob->fRunCount = runCount; + cacheBlob->fPool = &fPool; + return cacheBlob; +} + +void GrTextBlobCache::freeAll() { + SkTDynamicHash<GrAtlasTextBlob, GrAtlasTextBlob::Key>::Iter iter(&fCache); + while (!iter.done()) { + GrAtlasTextBlob* blob = &(*iter); + fBlobList.remove(blob); + blob->unref(); + ++iter; + } + fCache.rewind(); +} |