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

Unified Diff: src/gpu/GrTextBlobCache.cpp

Issue 1055843002: Adding a cache + memory pool for GPU TextBlobs (Closed) Base URL: https://skia.googlesource.com/skia.git@atlastext2
Patch Set: feedback inc 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrTextBlobCache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrTextBlobCache.cpp
diff --git a/src/gpu/GrTextBlobCache.cpp b/src/gpu/GrTextBlobCache.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9141b1712ad67c26c3f32360bb3dd01dc3208b37
--- /dev/null
+++ b/src/gpu/GrTextBlobCache.cpp
@@ -0,0 +1,45 @@
+/*
+ * 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() {
+ SkTDynamicHash<BitmapTextBlob, uint32_t>::Iter iter(&fCache);
+ while (!iter.done()) {
+ (&(*iter))->unref();
+ ++iter;
+ }
+}
+
+GrAtlasTextContext::BitmapTextBlob* GrTextBlobCache::createBlob(int glyphCount, int runCount,
+ size_t maxVASize) {
+ // We allocate size for the BitmapTextBlob itself, plus size for the vertices array,
+ // and size for the glyphIds array.
+ size_t verticesCount = glyphCount * kVerticesPerGlyph * maxVASize;
+ size_t size = sizeof(BitmapTextBlob) +
+ verticesCount +
+ glyphCount * sizeof(GrGlyph::PackedID) +
+ sizeof(BitmapTextBlob::Run) * runCount;
+
+ BitmapTextBlob* cacheBlob = SkNEW_PLACEMENT(fPool.allocate(size), BitmapTextBlob);
+
+ // setup offsets for vertices / glyphs
+ cacheBlob->fVertices = sizeof(BitmapTextBlob) + reinterpret_cast<unsigned char*>(cacheBlob);
+ cacheBlob->fGlyphIDs =
+ reinterpret_cast<GrGlyph::PackedID*>(cacheBlob->fVertices + verticesCount);
+ cacheBlob->fRuns = reinterpret_cast<BitmapTextBlob::Run*>(cacheBlob->fGlyphIDs + glyphCount);
+
+ // Initialize runs
+ for (int i = 0; i < runCount; i++) {
+ SkNEW_PLACEMENT(&cacheBlob->fRuns[i], BitmapTextBlob::Run);
+ }
+ cacheBlob->fRunCount = runCount;
+ cacheBlob->fPool = &fPool;
+ return cacheBlob;
+}
« no previous file with comments | « src/gpu/GrTextBlobCache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698