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

Unified Diff: src/gpu/GrAtlasTextContext.cpp

Issue 1088533002: Convert BitmapTextBatch from STArray to AutoSTMalloc (Closed) Base URL: https://skia.googlesource.com/skia.git@attryst
Patch Set: tweaks 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 | « no previous file | no next file » | 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 97e8a09c2b24948c351907fafde22bbaf0022205..8e610fbb722f48897e1eaffa72ac857a6f61c8c8 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -782,15 +782,7 @@ public:
typedef Blob::Run Run;
typedef Run::SubRunInfo TextInfo;
struct Geometry {
bsalomon 2015/04/13 15:06:16 SubRunGeometry?
- Geometry() {}
- Geometry(const Geometry& geometry)
- : fBlob(SkRef(geometry.fBlob.get()))
- , fRun(geometry.fRun)
- , fSubRun(geometry.fSubRun)
- , fColor(geometry.fColor)
- , fTransX(geometry.fTransX)
- , fTransY(geometry.fTransY) {}
- SkAutoTUnref<Blob> fBlob;
+ Blob* fBlob;
int fRun;
int fSubRun;
GrColor fColor;
@@ -798,9 +790,9 @@ public:
SkScalar fTransY;
};
- static GrBatch* Create(const Geometry& geometry, GrMaskFormat maskFormat,
- int glyphCount, GrBatchFontCache* fontCache) {
- return SkNEW_ARGS(BitmapTextBatch, (geometry, maskFormat, glyphCount, fontCache));
+ static BitmapTextBatch* Create(GrMaskFormat maskFormat, int glyphCount,
+ GrBatchFontCache* fontCache) {
+ return SkNEW_ARGS(BitmapTextBatch, (maskFormat, glyphCount, fontCache));
}
const char* name() const override { return "BitmapTextBatch"; }
@@ -876,7 +868,7 @@ public:
this->initDraw(batchTarget, gp, pipeline);
int glyphCount = this->numGlyphs();
- int instanceCount = fGeoData.count();
+ int instanceCount = fInstanceCount;
const GrVertexBuffer* vertexBuffer;
int firstVertex;
@@ -1018,19 +1010,32 @@ public:
this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDraw);
}
- SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
+ static const int kMinAllocated = 32;
bsalomon 2015/04/13 15:06:16 min allocated for what? is it a count or a bytes?
+ size_t instanceCount() const { return fInstanceCount; }
bsalomon 2015/04/13 15:06:16 instances of what?
+ SkAutoSTMalloc<kMinAllocated, Geometry>* geoData() { return &fGeoData; }
+
+ Geometry& geometry() { return fGeoData[0]; }
bsalomon 2015/04/13 15:06:16 comment about why we have a getter just for the fi
+ void init() {
+ fBatch.fColor = fGeoData[0].fColor;
+ fBatch.fViewMatrix = fGeoData[0].fBlob->fViewMatrix;
+ }
private:
- BitmapTextBatch(const Geometry& geometry, GrMaskFormat maskFormat,
+ BitmapTextBatch(GrMaskFormat maskFormat,
int glyphCount, GrBatchFontCache* fontCache)
: fMaskFormat(maskFormat)
, fPixelConfig(fontCache->getPixelConfig(maskFormat))
, fFontCache(fontCache) {
this->initClassID<BitmapTextBatch>();
- fGeoData.push_back(geometry);
- fBatch.fColor = geometry.fColor;
- fBatch.fViewMatrix = geometry.fBlob->fViewMatrix;
fBatch.fNumGlyphs = glyphCount;
+ fInstanceCount = 1;
+ fAllocatedCount = kMinAllocated;
+ }
+
+ ~BitmapTextBatch() {
+ for (size_t i = 0; i < fInstanceCount; i++) {
+ fGeoData[i].fBlob->unref();
+ }
}
void regenerateTextureCoords(GrGlyph* glyph, intptr_t vertex, size_t vertexStride) {
@@ -1133,7 +1138,25 @@ private:
}
fBatch.fNumGlyphs += that->numGlyphs();
- fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin());
+
+ // copy that->geoData(). We do this manually for performance reasons
+ SkAutoSTMalloc<kMinAllocated, Geometry>* otherGeoData = that->geoData();
+ size_t otherInstanceCount = that->instanceCount();
+ size_t allocSize = otherInstanceCount + fInstanceCount;
+ if (allocSize > fAllocatedCount) {
+ while (allocSize > fAllocatedCount) {
+ fAllocatedCount = fAllocatedCount << 1;
+ }
+ fGeoData.realloc(fAllocatedCount);
+ }
+
+ memcpy(&fGeoData[fInstanceCount], otherGeoData->get(),
+ otherInstanceCount * sizeof(Geometry));
+ size_t total = fInstanceCount + otherInstanceCount;
+ for (size_t i = fInstanceCount; i < total; i++) {
+ fGeoData[i].fBlob->ref();
+ }
+ fInstanceCount = total;
return true;
}
@@ -1147,7 +1170,10 @@ private:
};
BatchTracker fBatch;
- SkSTArray<1, Geometry, true> fGeoData;
+ SkAutoSTMalloc<kMinAllocated, Geometry> fGeoData;
+ size_t fInstanceCount;
+ size_t fAllocatedCount;
+ //SkSTArray<1, Geometry, true> fGeoData;
GrMaskFormat fMaskFormat;
GrPixelConfig fPixelConfig;
GrBatchFontCache* fFontCache;
@@ -1201,15 +1227,16 @@ inline void GrAtlasTextContext::flushRun(GrDrawTarget* target, GrPipelineBuilder
SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAlpha) :
color;
- BitmapTextBatch::Geometry geometry;
- geometry.fBlob.reset(SkRef(cacheBlob));
+ SkAutoTUnref<BitmapTextBatch> batch(BitmapTextBatch::Create(format, glyphCount,
+ fContext->getBatchFontCache()));
+ BitmapTextBatch::Geometry& geometry = batch->geometry();
+ geometry.fBlob = SkRef(cacheBlob);
geometry.fRun = run;
geometry.fSubRun = static_cast<int>(subRun);
geometry.fColor = subRunColor;
geometry.fTransX = transX;
geometry.fTransY = transY;
- SkAutoTUnref<GrBatch> batch(BitmapTextBatch::Create(geometry, format, glyphCount,
- fContext->getBatchFontCache()));
+ batch->init();
target->drawBatch(pipelineBuilder, batch, &cacheBlob->fRuns[run].fVertexBounds);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698