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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "GrAtlasTextContext.h" 7 #include "GrAtlasTextContext.h"
8 8
9 #include "GrAtlas.h" 9 #include "GrAtlas.h"
10 #include "GrBatch.h" 10 #include "GrBatch.h"
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 774
775 subRun->fGlyphEndIndex++; 775 subRun->fGlyphEndIndex++;
776 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph; 776 subRun->fVertexEndIndex += vertexStride * kVerticesPerGlyph;
777 } 777 }
778 778
779 class BitmapTextBatch : public GrBatch { 779 class BitmapTextBatch : public GrBatch {
780 public: 780 public:
781 typedef GrAtlasTextContext::BitmapTextBlob Blob; 781 typedef GrAtlasTextContext::BitmapTextBlob Blob;
782 typedef Blob::Run Run; 782 typedef Blob::Run Run;
783 typedef Run::SubRunInfo TextInfo; 783 typedef Run::SubRunInfo TextInfo;
784 struct Geometry { 784 struct Geometry {
bsalomon 2015/04/13 15:06:16 SubRunGeometry?
785 Geometry() {} 785 Blob* fBlob;
786 Geometry(const Geometry& geometry)
787 : fBlob(SkRef(geometry.fBlob.get()))
788 , fRun(geometry.fRun)
789 , fSubRun(geometry.fSubRun)
790 , fColor(geometry.fColor)
791 , fTransX(geometry.fTransX)
792 , fTransY(geometry.fTransY) {}
793 SkAutoTUnref<Blob> fBlob;
794 int fRun; 786 int fRun;
795 int fSubRun; 787 int fSubRun;
796 GrColor fColor; 788 GrColor fColor;
797 SkScalar fTransX; 789 SkScalar fTransX;
798 SkScalar fTransY; 790 SkScalar fTransY;
799 }; 791 };
800 792
801 static GrBatch* Create(const Geometry& geometry, GrMaskFormat maskFormat, 793 static BitmapTextBatch* Create(GrMaskFormat maskFormat, int glyphCount,
802 int glyphCount, GrBatchFontCache* fontCache) { 794 GrBatchFontCache* fontCache) {
803 return SkNEW_ARGS(BitmapTextBatch, (geometry, maskFormat, glyphCount, fo ntCache)); 795 return SkNEW_ARGS(BitmapTextBatch, (maskFormat, glyphCount, fontCache));
804 } 796 }
805 797
806 const char* name() const override { return "BitmapTextBatch"; } 798 const char* name() const override { return "BitmapTextBatch"; }
807 799
808 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { 800 void getInvariantOutputColor(GrInitInvariantOutput* out) const override {
809 if (kARGB_GrMaskFormat == fMaskFormat) { 801 if (kARGB_GrMaskFormat == fMaskFormat) {
810 out->setUnknownFourComponents(); 802 out->setUnknownFourComponents();
811 } else { 803 } else {
812 out->setKnownFourComponents(fBatch.fColor); 804 out->setKnownFourComponents(fBatch.fColor);
813 } 805 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 fMaskFormat, 861 fMaskFormat,
870 opaqueVertexColors, 862 opaqueVertexColors,
871 localMatrix)); 863 localMatrix));
872 864
873 size_t vertexStride = gp->getVertexStride(); 865 size_t vertexStride = gp->getVertexStride();
874 SkASSERT(vertexStride == get_vertex_stride(fMaskFormat)); 866 SkASSERT(vertexStride == get_vertex_stride(fMaskFormat));
875 867
876 this->initDraw(batchTarget, gp, pipeline); 868 this->initDraw(batchTarget, gp, pipeline);
877 869
878 int glyphCount = this->numGlyphs(); 870 int glyphCount = this->numGlyphs();
879 int instanceCount = fGeoData.count(); 871 int instanceCount = fInstanceCount;
880 const GrVertexBuffer* vertexBuffer; 872 const GrVertexBuffer* vertexBuffer;
881 int firstVertex; 873 int firstVertex;
882 874
883 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, 875 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride,
884 glyphCount * kVert icesPerGlyph, 876 glyphCount * kVert icesPerGlyph,
885 &vertexBuffer, 877 &vertexBuffer,
886 &firstVertex); 878 &firstVertex);
887 if (!vertices) { 879 if (!vertices) {
888 SkDebugf("Could not allocate vertices\n"); 880 SkDebugf("Could not allocate vertices\n");
889 return; 881 return;
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 // now copy all vertices 1003 // now copy all vertices
1012 size_t byteCount = info.fVertexEndIndex - info.fVertexStartIndex; 1004 size_t byteCount = info.fVertexEndIndex - info.fVertexStartIndex;
1013 memcpy(currVertex, blob->fVertices + info.fVertexStartIndex, byteCou nt); 1005 memcpy(currVertex, blob->fVertices + info.fVertexStartIndex, byteCou nt);
1014 1006
1015 currVertex += byteCount; 1007 currVertex += byteCount;
1016 } 1008 }
1017 1009
1018 this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDra w); 1010 this->flush(batchTarget, &drawInfo, instancesToFlush, maxInstancesPerDra w);
1019 } 1011 }
1020 1012
1021 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 1013 static const int kMinAllocated = 32;
bsalomon 2015/04/13 15:06:16 min allocated for what? is it a count or a bytes?
1014 size_t instanceCount() const { return fInstanceCount; }
bsalomon 2015/04/13 15:06:16 instances of what?
1015 SkAutoSTMalloc<kMinAllocated, Geometry>* geoData() { return &fGeoData; }
1016
1017 Geometry& geometry() { return fGeoData[0]; }
bsalomon 2015/04/13 15:06:16 comment about why we have a getter just for the fi
1018 void init() {
1019 fBatch.fColor = fGeoData[0].fColor;
1020 fBatch.fViewMatrix = fGeoData[0].fBlob->fViewMatrix;
1021 }
1022 1022
1023 private: 1023 private:
1024 BitmapTextBatch(const Geometry& geometry, GrMaskFormat maskFormat, 1024 BitmapTextBatch(GrMaskFormat maskFormat,
1025 int glyphCount, GrBatchFontCache* fontCache) 1025 int glyphCount, GrBatchFontCache* fontCache)
1026 : fMaskFormat(maskFormat) 1026 : fMaskFormat(maskFormat)
1027 , fPixelConfig(fontCache->getPixelConfig(maskFormat)) 1027 , fPixelConfig(fontCache->getPixelConfig(maskFormat))
1028 , fFontCache(fontCache) { 1028 , fFontCache(fontCache) {
1029 this->initClassID<BitmapTextBatch>(); 1029 this->initClassID<BitmapTextBatch>();
1030 fGeoData.push_back(geometry);
1031 fBatch.fColor = geometry.fColor;
1032 fBatch.fViewMatrix = geometry.fBlob->fViewMatrix;
1033 fBatch.fNumGlyphs = glyphCount; 1030 fBatch.fNumGlyphs = glyphCount;
1031 fInstanceCount = 1;
1032 fAllocatedCount = kMinAllocated;
1033 }
1034
1035 ~BitmapTextBatch() {
1036 for (size_t i = 0; i < fInstanceCount; i++) {
1037 fGeoData[i].fBlob->unref();
1038 }
1034 } 1039 }
1035 1040
1036 void regenerateTextureCoords(GrGlyph* glyph, intptr_t vertex, size_t vertexS tride) { 1041 void regenerateTextureCoords(GrGlyph* glyph, intptr_t vertex, size_t vertexS tride) {
1037 int width = glyph->fBounds.width(); 1042 int width = glyph->fBounds.width();
1038 int height = glyph->fBounds.height(); 1043 int height = glyph->fBounds.height();
1039 int u0 = glyph->fAtlasLocation.fX; 1044 int u0 = glyph->fAtlasLocation.fX;
1040 int v0 = glyph->fAtlasLocation.fY; 1045 int v0 = glyph->fAtlasLocation.fY;
1041 int u1 = u0 + width; 1046 int u1 = u0 + width;
1042 int v1 = v0 + height; 1047 int v1 = v0 + height;
1043 1048
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 1131
1127 if (this->fMaskFormat != kA8_GrMaskFormat && this->color() != that->colo r()) { 1132 if (this->fMaskFormat != kA8_GrMaskFormat && this->color() != that->colo r()) {
1128 return false; 1133 return false;
1129 } 1134 }
1130 1135
1131 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi ewMatrix())) { 1136 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi ewMatrix())) {
1132 return false; 1137 return false;
1133 } 1138 }
1134 1139
1135 fBatch.fNumGlyphs += that->numGlyphs(); 1140 fBatch.fNumGlyphs += that->numGlyphs();
1136 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; 1141
1142 // copy that->geoData(). We do this manually for performance reasons
1143 SkAutoSTMalloc<kMinAllocated, Geometry>* otherGeoData = that->geoData();
1144 size_t otherInstanceCount = that->instanceCount();
1145 size_t allocSize = otherInstanceCount + fInstanceCount;
1146 if (allocSize > fAllocatedCount) {
1147 while (allocSize > fAllocatedCount) {
1148 fAllocatedCount = fAllocatedCount << 1;
1149 }
1150 fGeoData.realloc(fAllocatedCount);
1151 }
1152
1153 memcpy(&fGeoData[fInstanceCount], otherGeoData->get(),
1154 otherInstanceCount * sizeof(Geometry));
1155 size_t total = fInstanceCount + otherInstanceCount;
1156 for (size_t i = fInstanceCount; i < total; i++) {
1157 fGeoData[i].fBlob->ref();
1158 }
1159 fInstanceCount = total;
1137 return true; 1160 return true;
1138 } 1161 }
1139 1162
1140 struct BatchTracker { 1163 struct BatchTracker {
1141 GrColor fColor; 1164 GrColor fColor;
1142 SkMatrix fViewMatrix; 1165 SkMatrix fViewMatrix;
1143 bool fUsesLocalCoords; 1166 bool fUsesLocalCoords;
1144 bool fColorIgnored; 1167 bool fColorIgnored;
1145 bool fCoverageIgnored; 1168 bool fCoverageIgnored;
1146 int fNumGlyphs; 1169 int fNumGlyphs;
1147 }; 1170 };
1148 1171
1149 BatchTracker fBatch; 1172 BatchTracker fBatch;
1150 SkSTArray<1, Geometry, true> fGeoData; 1173 SkAutoSTMalloc<kMinAllocated, Geometry> fGeoData;
1174 size_t fInstanceCount;
1175 size_t fAllocatedCount;
1176 //SkSTArray<1, Geometry, true> fGeoData;
1151 GrMaskFormat fMaskFormat; 1177 GrMaskFormat fMaskFormat;
1152 GrPixelConfig fPixelConfig; 1178 GrPixelConfig fPixelConfig;
1153 GrBatchFontCache* fFontCache; 1179 GrBatchFontCache* fFontCache;
1154 }; 1180 };
1155 1181
1156 void GrAtlasTextContext::flushRunAsPaths(const SkTextBlob::RunIterator& it, cons t SkPaint& skPaint, 1182 void GrAtlasTextContext::flushRunAsPaths(const SkTextBlob::RunIterator& it, cons t SkPaint& skPaint,
1157 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix, 1183 SkDrawFilter* drawFilter, const SkMatri x& viewMatrix,
1158 const SkIRect& clipBounds, SkScalar x, SkScalar y) { 1184 const SkIRect& clipBounds, SkScalar x, SkScalar y) {
1159 SkPaint runPaint = skPaint; 1185 SkPaint runPaint = skPaint;
1160 1186
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; 1220 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex;
1195 if (0 == glyphCount) { 1221 if (0 == glyphCount) {
1196 continue; 1222 continue;
1197 } 1223 }
1198 1224
1199 GrMaskFormat format = info.fMaskFormat; 1225 GrMaskFormat format = info.fMaskFormat;
1200 GrColor subRunColor = kARGB_GrMaskFormat == format ? 1226 GrColor subRunColor = kARGB_GrMaskFormat == format ?
1201 SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAlpha) : 1227 SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha, paintAlpha) :
1202 color; 1228 color;
1203 1229
1204 BitmapTextBatch::Geometry geometry; 1230 SkAutoTUnref<BitmapTextBatch> batch(BitmapTextBatch::Create(format, glyp hCount,
1205 geometry.fBlob.reset(SkRef(cacheBlob)); 1231 fContext->getBatchFo ntCache()));
1232 BitmapTextBatch::Geometry& geometry = batch->geometry();
1233 geometry.fBlob = SkRef(cacheBlob);
1206 geometry.fRun = run; 1234 geometry.fRun = run;
1207 geometry.fSubRun = static_cast<int>(subRun); 1235 geometry.fSubRun = static_cast<int>(subRun);
1208 geometry.fColor = subRunColor; 1236 geometry.fColor = subRunColor;
1209 geometry.fTransX = transX; 1237 geometry.fTransX = transX;
1210 geometry.fTransY = transY; 1238 geometry.fTransY = transY;
1211 SkAutoTUnref<GrBatch> batch(BitmapTextBatch::Create(geometry, format, gl yphCount, 1239 batch->init();
1212 fContext->getBatchFo ntCache()));
1213 1240
1214 target->drawBatch(pipelineBuilder, batch, &cacheBlob->fRuns[run].fVertex Bounds); 1241 target->drawBatch(pipelineBuilder, batch, &cacheBlob->fRuns[run].fVertex Bounds);
1215 } 1242 }
1216 } 1243 }
1217 1244
1218 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend erTarget* rt, 1245 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend erTarget* rt,
1219 const GrPaint& grPaint, const GrC lip& clip, 1246 const GrPaint& grPaint, const GrC lip& clip,
1220 SkScalar transX, SkScalar transY) { 1247 SkScalar transX, SkScalar transY) {
1221 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { 1248 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) {
1222 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; 1249 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i];
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 1305
1279 GrColor color = grPaint.getColor(); 1306 GrColor color = grPaint.getColor();
1280 uint8_t paintAlpha = skPaint.getAlpha(); 1307 uint8_t paintAlpha = skPaint.getAlpha();
1281 for (int run = 0; run < cacheBlob->fRunCount; run++) { 1308 for (int run = 0; run < cacheBlob->fRunCount; run++) {
1282 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, paintAlp ha, 0, 0); 1309 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, paintAlp ha, 0, 0);
1283 } 1310 }
1284 1311
1285 // Now flush big glyphs 1312 // Now flush big glyphs
1286 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); 1313 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0);
1287 } 1314 }
OLDNEW
« 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