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

Unified Diff: src/gpu/GrAtlasTextContext.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/GrAtlasTextContext.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAtlasTextContext.cpp
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index 38edc8e55881bc7e8cb7251303f14821b9f43b98..d6bb3e079712ecb27c9996786cf741e228a197dc 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -15,6 +15,7 @@
#include "GrFontScaler.h"
#include "GrIndexBuffer.h"
#include "GrStrokeInfo.h"
+#include "GrTextBlobCache.h"
#include "GrTexturePriv.h"
#include "SkAutoKern.h"
@@ -67,16 +68,13 @@ static size_t get_vertex_stride(GrMaskFormat maskFormat) {
GrAtlasTextContext::GrAtlasTextContext(GrContext* context,
SkGpuDevice* gpuDevice,
const SkDeviceProperties& properties)
- : INHERITED(context, gpuDevice, properties) {
+ : INHERITED(context, gpuDevice, properties) {
+ // We overallocate vertices in our textblobs based on the assumption that A8 has the greatest
+ // vertexStride
+ SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCDTextVASize,
+ vertex_attribute_changed);
fCurrStrike = NULL;
-}
-
-void GrAtlasTextContext::ClearCacheEntry(uint32_t key, BitmapTextBlob** blob) {
- (*blob)->unref();
-}
-
-GrAtlasTextContext::~GrAtlasTextContext() {
- fCache.foreach(&GrAtlasTextContext::ClearCacheEntry);
+ fCache = context->getTextBlobCache();
}
GrAtlasTextContext* GrAtlasTextContext::Create(GrContext* context,
@@ -110,72 +108,29 @@ inline SkGlyphCache* GrAtlasTextContext::setupCache(BitmapTextBlob::Run* run,
return SkGlyphCache::DetachCache(run->fTypeface, run->fDescriptor.getDesc());
}
-inline void GrAtlasTextContext::BlobGlyphCount(int* glyphCount, int* runCount,
- const SkTextBlob* blob) {
- SkTextBlob::RunIterator itCounter(blob);
- for (; !itCounter.done(); itCounter.next(), (*runCount)++) {
- *glyphCount += itCounter.glyphCount();
- }
-}
-
-GrAtlasTextContext::BitmapTextBlob* GrAtlasTextContext::CreateBlob(int glyphCount,
- int runCount) {
- // We allocate size for the BitmapTextBlob itself, plus size for the vertices array,
- // and size for the glyphIds array.
- SK_COMPILE_ASSERT(kGrayTextVASize >= kColorTextVASize && kGrayTextVASize >= kLCDTextVASize,
- vertex_attribute_changed);
- size_t verticesCount = glyphCount * kVerticesPerGlyph * kGrayTextVASize;
- size_t length = sizeof(BitmapTextBlob) +
- verticesCount +
- glyphCount * sizeof(GrGlyph::PackedID) +
- sizeof(BitmapTextBlob::Run) * runCount;
-
- BitmapTextBlob* cacheBlob = SkNEW_PLACEMENT(sk_malloc_throw(length), 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;
- return cacheBlob;
-}
-
void GrAtlasTextContext::drawTextBlob(GrRenderTarget* rt, const GrClip& clip,
const SkPaint& skPaint, const SkMatrix& viewMatrix,
const SkTextBlob* blob, SkScalar x, SkScalar y,
SkDrawFilter* drawFilter, const SkIRect& clipBounds) {
- BitmapTextBlob* cacheBlob;
- BitmapTextBlob** foundBlob = fCache.find(blob->uniqueID());
+ uint32_t uniqueID = blob->uniqueID();
+ BitmapTextBlob* cacheBlob = fCache->find(uniqueID);
SkIRect clipRect;
clip.getConservativeBounds(rt->width(), rt->height(), &clipRect);
- if (foundBlob) {
- cacheBlob = *foundBlob;
+ if (cacheBlob) {
if (MustRegenerateBlob(*cacheBlob, skPaint, viewMatrix, x, y)) {
// We have to remake the blob because changes may invalidate our masks.
// TODO we could probably get away reuse most of the time if the pointer is unique,
// but we'd have to clear the subrun information
- cacheBlob->unref();
- int glyphCount = 0;
- int runCount = 0;
- BlobGlyphCount(&glyphCount, &runCount, blob);
- cacheBlob = CreateBlob(glyphCount, runCount);
- fCache.set(blob->uniqueID(), cacheBlob);
+ fCache->remove(cacheBlob);
+ cacheBlob = fCache->createCachedBlob(blob, kGrayTextVASize);
this->regenerateTextBlob(cacheBlob, skPaint, viewMatrix, blob, x, y, drawFilter,
clipRect);
+ } else {
+ fCache->makeMRU(cacheBlob);
}
} else {
- int glyphCount = 0;
- int runCount = 0;
- BlobGlyphCount(&glyphCount, &runCount, blob);
- cacheBlob = CreateBlob(glyphCount, runCount);
- fCache.set(blob->uniqueID(), cacheBlob);
+ cacheBlob = fCache->createCachedBlob(blob, kGrayTextVASize);
this->regenerateTextBlob(cacheBlob, skPaint, viewMatrix, blob, x, y, drawFilter, clipRect);
}
@@ -269,7 +224,7 @@ void GrAtlasTextContext::onDrawText(GrRenderTarget* rt, const GrClip& clip,
const char text[], size_t byteLength,
SkScalar x, SkScalar y, const SkIRect& regionClipBounds) {
int glyphCount = skPaint.countText(text, byteLength);
- SkAutoTUnref<BitmapTextBlob> blob(CreateBlob(glyphCount, 1));
+ SkAutoTUnref<BitmapTextBlob> blob(fCache->createBlob(glyphCount, 1, kGrayTextVASize));
blob->fViewMatrix = viewMatrix;
blob->fX = x;
blob->fY = y;
@@ -383,7 +338,7 @@ void GrAtlasTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset, const SkIRect& regionClipBounds) {
int glyphCount = skPaint.countText(text, byteLength);
- SkAutoTUnref<BitmapTextBlob> blob(CreateBlob(glyphCount, 1));
+ SkAutoTUnref<BitmapTextBlob> blob(fCache->createBlob(glyphCount, 1, kGrayTextVASize));
blob->fStyle = skPaint.getStyle();
blob->fViewMatrix = viewMatrix;
« no previous file with comments | « src/gpu/GrAtlasTextContext.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698