aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2016-02-10 11:55:52 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-10 11:55:52 -0800
commit923037724231f11b9249dbb5bf9688835b5ff9b0 (patch)
tree8c827edfa396d0116fb4069d2f29f5f2acf81d89 /src/gpu/text
parent60ae6b0e3299db06f53bf39f96df8a304583b043 (diff)
Remove GrTextBlobCache/GrAtlasTextBlob friendliness
Diffstat (limited to 'src/gpu/text')
-rw-r--r--src/gpu/text/GrAtlasTextBlob.cpp32
-rw-r--r--src/gpu/text/GrAtlasTextBlob.h41
-rw-r--r--src/gpu/text/GrAtlasTextContext.cpp17
-rw-r--r--src/gpu/text/GrTextBlobCache.cpp33
-rw-r--r--src/gpu/text/GrTextBlobCache.h34
5 files changed, 79 insertions, 78 deletions
diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp
index cac1e53f09..2775098ecc 100644
--- a/src/gpu/text/GrAtlasTextBlob.cpp
+++ b/src/gpu/text/GrAtlasTextBlob.cpp
@@ -17,6 +17,38 @@
#include "SkTextBlobRunIterator.h"
#include "batches/GrAtlasTextBatch.h"
+GrAtlasTextBlob* GrAtlasTextBlob::Create(GrMemoryPool* pool, int glyphCount, int runCount) {
+ // We allocate size for the GrAtlasTextBlob itself, plus size for the vertices array,
+ // and size for the glyphIds array.
+ size_t verticesCount = glyphCount * kVerticesPerGlyph * kMaxVASize;
+ size_t size = sizeof(GrAtlasTextBlob) +
+ verticesCount +
+ glyphCount * sizeof(GrGlyph**) +
+ sizeof(GrAtlasTextBlob::Run) * runCount;
+
+ void* allocation = pool->allocate(size);
+ if (CACHE_SANITY_CHECK) {
+ sk_bzero(allocation, size);
+ }
+
+ GrAtlasTextBlob* cacheBlob = new (allocation) GrAtlasTextBlob;
+ cacheBlob->fSize = size;
+
+ // 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 = pool;
+ return cacheBlob;
+}
+
+
SkGlyphCache* GrAtlasTextBlob::setupCache(int runIndex,
const SkSurfaceProps& props,
const SkPaint& skPaint,
diff --git a/src/gpu/text/GrAtlasTextBlob.h b/src/gpu/text/GrAtlasTextBlob.h
index 4351aae748..68cba3d506 100644
--- a/src/gpu/text/GrAtlasTextBlob.h
+++ b/src/gpu/text/GrAtlasTextBlob.h
@@ -18,6 +18,7 @@
#include "SkTInternalLList.h"
struct GrDistanceFieldAdjustTable;
+class GrMemoryPool;
class GrTextContext;
class SkDrawFilter;
class SkTextBlob;
@@ -45,16 +46,7 @@ class GrAtlasTextBlob : public SkNVRefCnt<GrAtlasTextBlob> {
public:
SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrAtlasTextBlob);
- GrAtlasTextBlob()
- : fMaxMinScale(-SK_ScalarMax)
- , fMinMaxScale(SK_ScalarMax)
- , fTextType(0) {}
-
- ~GrAtlasTextBlob() {
- for (int i = 0; i < fRunCount; i++) {
- fRuns[i].~Run();
- }
- }
+ static GrAtlasTextBlob* Create(GrMemoryPool* pool, int glyphCount, int runCount);
struct Key {
Key() {
@@ -75,6 +67,20 @@ public:
}
};
+ void setupKey(const GrAtlasTextBlob::Key& key,
+ const SkMaskFilter::BlurRec& blurRec,
+ const SkPaint& paint) {
+ fKey = key;
+ if (key.fHasBlur) {
+ fBlurRec = blurRec;
+ }
+ if (key.fStyle != SkPaint::kFill_Style) {
+ fStrokeInfo.fFrameWidth = paint.getStrokeWidth();
+ fStrokeInfo.fMiterLimit = paint.getStrokeMiter();
+ fStrokeInfo.fJoin = paint.getStrokeJoin();
+ }
+ }
+
static const Key& GetKey(const GrAtlasTextBlob& blob) {
return blob.fKey;
}
@@ -198,6 +204,7 @@ public:
static const size_t kColorTextVASize = sizeof(SkPoint) + sizeof(SkIPoint16);
static const size_t kGrayTextVASize = sizeof(SkPoint) + sizeof(GrColor) + sizeof(SkIPoint16);
static const size_t kLCDTextVASize = kGrayTextVASize;
+ static const size_t kMaxVASize = kGrayTextVASize;
static const int kVerticesPerGlyph = 4;
static void AssertEqual(const GrAtlasTextBlob&, const GrAtlasTextBlob&);
@@ -220,7 +227,20 @@ public:
const GrDistanceFieldAdjustTable* distanceAdjustTable,
GrBatchFontCache* cache);
+ const Key& key() const { return fKey; }
+
+ ~GrAtlasTextBlob() {
+ for (int i = 0; i < fRunCount; i++) {
+ fRuns[i].~Run();
+ }
+ }
+
private:
+ GrAtlasTextBlob()
+ : fMaxMinScale(-SK_ScalarMax)
+ , fMinMaxScale(SK_ScalarMax)
+ , fTextType(0) {}
+
void appendLargeGlyph(GrGlyph* glyph, GrFontScaler* scaler, const SkGlyph& skGlyph,
SkScalar x, SkScalar y, SkScalar scale, bool applyVM);
@@ -456,7 +476,6 @@ private:
uint8_t fTextType;
friend class GrAtlasTextBatch; // We might be able to get rid of this friending
- friend class GrTextBlobCache; // Needs to access the key
};
#endif
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index 91fa658110..9e30476248 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -150,8 +150,7 @@ void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc,
// 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
fCache->remove(cacheBlob);
- cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint,
- GrAtlasTextBlob::kGrayTextVASize)));
+ cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint)));
this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix,
blob, x, y, drawFilter);
} else {
@@ -161,9 +160,8 @@ void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc,
int glyphCount = 0;
int runCount = 0;
GrTextBlobCache::BlobGlyphCount(&glyphCount, &runCount, blob);
- SkAutoTUnref<GrAtlasTextBlob> sanityBlob(
- fCache->createBlob(glyphCount, runCount, GrAtlasTextBlob::kGrayTextVASize));
- GrTextBlobCache::SetupCacheBlobKey(sanityBlob, key, blurRec, skPaint);
+ SkAutoTUnref<GrAtlasTextBlob> sanityBlob(fCache->createBlob(glyphCount, runCount));
+ sanityBlob->setupKey(key, blurRec, skPaint);
this->regenerateTextBlob(sanityBlob, skPaint, grPaint.getColor(), viewMatrix,
blob, x, y, drawFilter);
GrAtlasTextBlob::AssertEqual(*sanityBlob, *cacheBlob);
@@ -171,10 +169,9 @@ void GrAtlasTextContext::drawTextBlob(GrDrawContext* dc,
}
} else {
if (canCache) {
- cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint,
- GrAtlasTextBlob::kGrayTextVASize)));
+ cacheBlob.reset(SkRef(fCache->createCachedBlob(blob, key, blurRec, skPaint)));
} else {
- cacheBlob.reset(fCache->createBlob(blob, GrAtlasTextBlob::kGrayTextVASize));
+ cacheBlob.reset(fCache->createBlob(blob));
}
this->regenerateTextBlob(cacheBlob, skPaint, grPaint.getColor(), viewMatrix,
blob, x, y, drawFilter);
@@ -278,7 +275,7 @@ GrAtlasTextContext::createDrawTextBlob(const GrPaint& paint, const SkPaint& skPa
SkScalar x, SkScalar y) {
int glyphCount = skPaint.countText(text, byteLength);
- GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASize);
+ GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1);
blob->initThrowawayBlob(viewMatrix, x, y);
if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps,
@@ -301,7 +298,7 @@ GrAtlasTextContext::createDrawPosTextBlob(const GrPaint& paint, const SkPaint& s
const SkPoint& offset) {
int glyphCount = skPaint.countText(text, byteLength);
- GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1, GrAtlasTextBlob::kGrayTextVASize);
+ GrAtlasTextBlob* blob = fCache->createBlob(glyphCount, 1);
blob->initThrowawayBlob(viewMatrix, offset.x(), offset.y());
if (GrTextUtils::CanDrawAsDistanceFields(skPaint, viewMatrix, fSurfaceProps,
diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp
index 7fa2d1a80a..ce74977e49 100644
--- a/src/gpu/text/GrTextBlobCache.cpp
+++ b/src/gpu/text/GrTextBlobCache.cpp
@@ -7,43 +7,10 @@
#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);
- if (CACHE_SANITY_CHECK) {
- sk_bzero(allocation, size);
- }
-
- GrAtlasTextBlob* cacheBlob = new (allocation) GrAtlasTextBlob;
- cacheBlob->fSize = size;
-
- // 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()) {
diff --git a/src/gpu/text/GrTextBlobCache.h b/src/gpu/text/GrTextBlobCache.h
index 8eee9d13db..e3b2ca73fb 100644
--- a/src/gpu/text/GrTextBlobCache.h
+++ b/src/gpu/text/GrTextBlobCache.h
@@ -30,40 +30,26 @@ public:
~GrTextBlobCache();
// creates an uncached blob
- GrAtlasTextBlob* createBlob(int glyphCount, int runCount, size_t maxVASize);
- GrAtlasTextBlob* createBlob(const SkTextBlob* blob, size_t maxVAStride) {
+ GrAtlasTextBlob* createBlob(int glyphCount, int runCount) {
+ return GrAtlasTextBlob::Create(&fPool, glyphCount, runCount);
+ }
+ GrAtlasTextBlob* createBlob(const SkTextBlob* blob) {
int glyphCount = 0;
int runCount = 0;
BlobGlyphCount(&glyphCount, &runCount, blob);
- GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxVAStride);
+ GrAtlasTextBlob* cacheBlob = GrAtlasTextBlob::Create(&fPool, glyphCount, runCount);
return cacheBlob;
}
- static void SetupCacheBlobKey(GrAtlasTextBlob* cacheBlob,
- const GrAtlasTextBlob::Key& key,
- const SkMaskFilter::BlurRec& blurRec,
- const SkPaint& paint) {
- cacheBlob->fKey = key;
- if (key.fHasBlur) {
- cacheBlob->fBlurRec = blurRec;
- }
- if (key.fStyle != SkPaint::kFill_Style) {
- cacheBlob->fStrokeInfo.fFrameWidth = paint.getStrokeWidth();
- cacheBlob->fStrokeInfo.fMiterLimit = paint.getStrokeMiter();
- cacheBlob->fStrokeInfo.fJoin = paint.getStrokeJoin();
- }
- }
-
GrAtlasTextBlob* createCachedBlob(const SkTextBlob* blob,
const GrAtlasTextBlob::Key& key,
const SkMaskFilter::BlurRec& blurRec,
- const SkPaint& paint,
- size_t maxVAStride) {
+ const SkPaint& paint) {
int glyphCount = 0;
int runCount = 0;
BlobGlyphCount(&glyphCount, &runCount, blob);
- GrAtlasTextBlob* cacheBlob = this->createBlob(glyphCount, runCount, maxVAStride);
- SetupCacheBlobKey(cacheBlob, key, blurRec, paint);
+ GrAtlasTextBlob* cacheBlob = GrAtlasTextBlob::Create(&fPool, glyphCount, runCount);
+ cacheBlob->setupKey(key, blurRec, paint);
this->add(cacheBlob);
return cacheBlob;
}
@@ -73,7 +59,7 @@ public:
}
void remove(GrAtlasTextBlob* blob) {
- fCache.remove(blob->fKey);
+ fCache.remove(blob->key());
fBlobList.remove(blob);
blob->unref();
}
@@ -119,7 +105,7 @@ private:
iter.init(fBlobList, BitmapBlobList::Iter::kTail_IterStart);
GrAtlasTextBlob* lruBlob = nullptr;
while (fPool.size() > fBudget && (lruBlob = iter.get()) && lruBlob != blob) {
- fCache.remove(lruBlob->fKey);
+ fCache.remove(lruBlob->key());
// Backup the iterator before removing and unrefing the blob
iter.prev();