| OLD | NEW |
| 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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 { |
| 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 Loading... |
| 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 Loading... |
| 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 // The minimum number of Geometry we will try to allocate. |
| 1014 static const int kMinAllocated = 32; |
| 1015 |
| 1016 // Total number of Geometry this Batch owns |
| 1017 int instanceCount() const { return fInstanceCount; } |
| 1018 SkAutoSTMalloc<kMinAllocated, Geometry>* geoData() { return &fGeoData; } |
| 1019 |
| 1020 // to avoid even the initial copy of the struct, we have a getter for the fi
rst item which |
| 1021 // is used to seed the batch with its initial geometry. After seeding, the
client should call |
| 1022 // init() so the Batch can initialize itself |
| 1023 Geometry& geometry() { return fGeoData[0]; } |
| 1024 void init() { |
| 1025 fBatch.fColor = fGeoData[0].fColor; |
| 1026 fBatch.fViewMatrix = fGeoData[0].fBlob->fViewMatrix; |
| 1027 } |
| 1022 | 1028 |
| 1023 private: | 1029 private: |
| 1024 BitmapTextBatch(const Geometry& geometry, GrMaskFormat maskFormat, | 1030 BitmapTextBatch(GrMaskFormat maskFormat, |
| 1025 int glyphCount, GrBatchFontCache* fontCache) | 1031 int glyphCount, GrBatchFontCache* fontCache) |
| 1026 : fMaskFormat(maskFormat) | 1032 : fMaskFormat(maskFormat) |
| 1027 , fPixelConfig(fontCache->getPixelConfig(maskFormat)) | 1033 , fPixelConfig(fontCache->getPixelConfig(maskFormat)) |
| 1028 , fFontCache(fontCache) { | 1034 , fFontCache(fontCache) { |
| 1029 this->initClassID<BitmapTextBatch>(); | 1035 this->initClassID<BitmapTextBatch>(); |
| 1030 fGeoData.push_back(geometry); | |
| 1031 fBatch.fColor = geometry.fColor; | |
| 1032 fBatch.fViewMatrix = geometry.fBlob->fViewMatrix; | |
| 1033 fBatch.fNumGlyphs = glyphCount; | 1036 fBatch.fNumGlyphs = glyphCount; |
| 1037 fInstanceCount = 1; |
| 1038 fAllocatedCount = kMinAllocated; |
| 1039 } |
| 1040 |
| 1041 ~BitmapTextBatch() { |
| 1042 for (int i = 0; i < fInstanceCount; i++) { |
| 1043 fGeoData[i].fBlob->unref(); |
| 1044 } |
| 1034 } | 1045 } |
| 1035 | 1046 |
| 1036 void regenerateTextureCoords(GrGlyph* glyph, intptr_t vertex, size_t vertexS
tride) { | 1047 void regenerateTextureCoords(GrGlyph* glyph, intptr_t vertex, size_t vertexS
tride) { |
| 1037 int width = glyph->fBounds.width(); | 1048 int width = glyph->fBounds.width(); |
| 1038 int height = glyph->fBounds.height(); | 1049 int height = glyph->fBounds.height(); |
| 1039 int u0 = glyph->fAtlasLocation.fX; | 1050 int u0 = glyph->fAtlasLocation.fX; |
| 1040 int v0 = glyph->fAtlasLocation.fY; | 1051 int v0 = glyph->fAtlasLocation.fY; |
| 1041 int u1 = u0 + width; | 1052 int u1 = u0 + width; |
| 1042 int v1 = v0 + height; | 1053 int v1 = v0 + height; |
| 1043 | 1054 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 | 1137 |
| 1127 if (this->fMaskFormat != kA8_GrMaskFormat && this->color() != that->colo
r()) { | 1138 if (this->fMaskFormat != kA8_GrMaskFormat && this->color() != that->colo
r()) { |
| 1128 return false; | 1139 return false; |
| 1129 } | 1140 } |
| 1130 | 1141 |
| 1131 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { | 1142 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { |
| 1132 return false; | 1143 return false; |
| 1133 } | 1144 } |
| 1134 | 1145 |
| 1135 fBatch.fNumGlyphs += that->numGlyphs(); | 1146 fBatch.fNumGlyphs += that->numGlyphs(); |
| 1136 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 1147 |
| 1148 // copy that->geoData(). We do this manually for performance reasons |
| 1149 SkAutoSTMalloc<kMinAllocated, Geometry>* otherGeoData = that->geoData(); |
| 1150 int otherInstanceCount = that->instanceCount(); |
| 1151 int allocSize = otherInstanceCount + fInstanceCount; |
| 1152 if (allocSize > fAllocatedCount) { |
| 1153 while (allocSize > fAllocatedCount) { |
| 1154 fAllocatedCount = fAllocatedCount << 1; |
| 1155 } |
| 1156 fGeoData.realloc(fAllocatedCount); |
| 1157 } |
| 1158 |
| 1159 memcpy(&fGeoData[fInstanceCount], otherGeoData->get(), |
| 1160 otherInstanceCount * sizeof(Geometry)); |
| 1161 int total = fInstanceCount + otherInstanceCount; |
| 1162 for (int i = fInstanceCount; i < total; i++) { |
| 1163 fGeoData[i].fBlob->ref(); |
| 1164 } |
| 1165 fInstanceCount = total; |
| 1137 return true; | 1166 return true; |
| 1138 } | 1167 } |
| 1139 | 1168 |
| 1140 struct BatchTracker { | 1169 struct BatchTracker { |
| 1141 GrColor fColor; | 1170 GrColor fColor; |
| 1142 SkMatrix fViewMatrix; | 1171 SkMatrix fViewMatrix; |
| 1143 bool fUsesLocalCoords; | 1172 bool fUsesLocalCoords; |
| 1144 bool fColorIgnored; | 1173 bool fColorIgnored; |
| 1145 bool fCoverageIgnored; | 1174 bool fCoverageIgnored; |
| 1146 int fNumGlyphs; | 1175 int fNumGlyphs; |
| 1147 }; | 1176 }; |
| 1148 | 1177 |
| 1149 BatchTracker fBatch; | 1178 BatchTracker fBatch; |
| 1150 SkSTArray<1, Geometry, true> fGeoData; | 1179 SkAutoSTMalloc<kMinAllocated, Geometry> fGeoData; |
| 1180 int fInstanceCount; |
| 1181 int fAllocatedCount; |
| 1151 GrMaskFormat fMaskFormat; | 1182 GrMaskFormat fMaskFormat; |
| 1152 GrPixelConfig fPixelConfig; | 1183 GrPixelConfig fPixelConfig; |
| 1153 GrBatchFontCache* fFontCache; | 1184 GrBatchFontCache* fFontCache; |
| 1154 }; | 1185 }; |
| 1155 | 1186 |
| 1156 void GrAtlasTextContext::flushRunAsPaths(const SkTextBlob::RunIterator& it, cons
t SkPaint& skPaint, | 1187 void GrAtlasTextContext::flushRunAsPaths(const SkTextBlob::RunIterator& it, cons
t SkPaint& skPaint, |
| 1157 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, | 1188 SkDrawFilter* drawFilter, const SkMatri
x& viewMatrix, |
| 1158 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { | 1189 const SkIRect& clipBounds, SkScalar x,
SkScalar y) { |
| 1159 SkPaint runPaint = skPaint; | 1190 SkPaint runPaint = skPaint; |
| 1160 | 1191 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; | 1225 int glyphCount = info.fGlyphEndIndex - info.fGlyphStartIndex; |
| 1195 if (0 == glyphCount) { | 1226 if (0 == glyphCount) { |
| 1196 continue; | 1227 continue; |
| 1197 } | 1228 } |
| 1198 | 1229 |
| 1199 GrMaskFormat format = info.fMaskFormat; | 1230 GrMaskFormat format = info.fMaskFormat; |
| 1200 GrColor subRunColor = kARGB_GrMaskFormat == format ? | 1231 GrColor subRunColor = kARGB_GrMaskFormat == format ? |
| 1201 SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha,
paintAlpha) : | 1232 SkColorSetARGB(paintAlpha, paintAlpha, paintAlpha,
paintAlpha) : |
| 1202 color; | 1233 color; |
| 1203 | 1234 |
| 1204 BitmapTextBatch::Geometry geometry; | 1235 SkAutoTUnref<BitmapTextBatch> batch(BitmapTextBatch::Create(format, glyp
hCount, |
| 1205 geometry.fBlob.reset(SkRef(cacheBlob)); | 1236 fContext->getBatchFo
ntCache())); |
| 1237 BitmapTextBatch::Geometry& geometry = batch->geometry(); |
| 1238 geometry.fBlob = SkRef(cacheBlob); |
| 1206 geometry.fRun = run; | 1239 geometry.fRun = run; |
| 1207 geometry.fSubRun = subRun; | 1240 geometry.fSubRun = subRun; |
| 1208 geometry.fColor = subRunColor; | 1241 geometry.fColor = subRunColor; |
| 1209 geometry.fTransX = transX; | 1242 geometry.fTransX = transX; |
| 1210 geometry.fTransY = transY; | 1243 geometry.fTransY = transY; |
| 1211 SkAutoTUnref<GrBatch> batch(BitmapTextBatch::Create(geometry, format, gl
yphCount, | 1244 batch->init(); |
| 1212 fContext->getBatchFo
ntCache())); | |
| 1213 | 1245 |
| 1214 target->drawBatch(pipelineBuilder, batch, &cacheBlob->fRuns[run].fVertex
Bounds); | 1246 target->drawBatch(pipelineBuilder, batch, &cacheBlob->fRuns[run].fVertex
Bounds); |
| 1215 } | 1247 } |
| 1216 } | 1248 } |
| 1217 | 1249 |
| 1218 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend
erTarget* rt, | 1250 inline void GrAtlasTextContext::flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRend
erTarget* rt, |
| 1219 const GrPaint& grPaint, const GrC
lip& clip, | 1251 const GrPaint& grPaint, const GrC
lip& clip, |
| 1220 SkScalar transX, SkScalar transY)
{ | 1252 SkScalar transX, SkScalar transY)
{ |
| 1221 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { | 1253 for (int i = 0; i < cacheBlob->fBigGlyphs.count(); i++) { |
| 1222 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; | 1254 BitmapTextBlob::BigGlyph& bigGlyph = cacheBlob->fBigGlyphs[i]; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1278 | 1310 |
| 1279 GrColor color = grPaint.getColor(); | 1311 GrColor color = grPaint.getColor(); |
| 1280 uint8_t paintAlpha = skPaint.getAlpha(); | 1312 uint8_t paintAlpha = skPaint.getAlpha(); |
| 1281 for (int run = 0; run < cacheBlob->fRunCount; run++) { | 1313 for (int run = 0; run < cacheBlob->fRunCount; run++) { |
| 1282 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, paintAlp
ha, 0, 0); | 1314 this->flushRun(target, &pipelineBuilder, cacheBlob, run, color, paintAlp
ha, 0, 0); |
| 1283 } | 1315 } |
| 1284 | 1316 |
| 1285 // Now flush big glyphs | 1317 // Now flush big glyphs |
| 1286 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); | 1318 this->flushBigGlyphs(cacheBlob, rt, grPaint, clip, 0, 0); |
| 1287 } | 1319 } |
| OLD | NEW |