| 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 | 7 |
| 8 #include "GrAtlasTextBatch.h" | 8 #include "GrAtlasTextBatch.h" |
| 9 | 9 |
| 10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 &flushInfo.fVertexOffset); | 125 &flushInfo.fVertexOffset); |
| 126 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); | 126 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); |
| 127 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuffer(
)); | 127 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuffer(
)); |
| 128 if (!vertices || !flushInfo.fVertexBuffer) { | 128 if (!vertices || !flushInfo.fVertexBuffer) { |
| 129 SkDebugf("Could not allocate vertices\n"); | 129 SkDebugf("Could not allocate vertices\n"); |
| 130 return; | 130 return; |
| 131 } | 131 } |
| 132 | 132 |
| 133 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); | 133 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); |
| 134 | 134 |
| 135 // We cache some values to avoid going to the glyphcache for the same fontSc
aler twice | |
| 136 // in a row | |
| 137 const SkDescriptor* desc = nullptr; | |
| 138 SkGlyphCache* cache = nullptr; | |
| 139 SkTypeface* typeface = nullptr; | |
| 140 | |
| 141 GrBlobRegenHelper helper(this, target, &flushInfo); | 135 GrBlobRegenHelper helper(this, target, &flushInfo); |
| 142 | 136 SkAutoGlyphCache glyphCache; |
| 143 for (int i = 0; i < fGeoCount; i++) { | 137 for (int i = 0; i < fGeoCount; i++) { |
| 144 const Geometry& args = fGeoData[i]; | 138 const Geometry& args = fGeoData[i]; |
| 145 Blob* blob = args.fBlob; | 139 Blob* blob = args.fBlob; |
| 146 size_t byteCount; | 140 size_t byteCount; |
| 147 void* blobVertices; | 141 void* blobVertices; |
| 148 int subRunGlyphCount; | 142 int subRunGlyphCount; |
| 149 blob->regenInBatch(target, fFontCache, &helper, args.fRun, args.fSubRun,
&cache, | 143 blob->regenInBatch(target, fFontCache, &helper, args.fRun, args.fSubRun,
&glyphCache, |
| 150 &typeface, &desc, vertexStride, args.fViewMatrix, arg
s.fX, | 144 vertexStride, args.fViewMatrix, args.fX, args.fY, arg
s.fColor, |
| 151 args.fY, args.fColor, &blobVertices, &byteCount, &sub
RunGlyphCount); | 145 &blobVertices, &byteCount, &subRunGlyphCount); |
| 152 | 146 |
| 153 // now copy all vertices | 147 // now copy all vertices |
| 154 memcpy(currVertex, blobVertices, byteCount); | 148 memcpy(currVertex, blobVertices, byteCount); |
| 155 | 149 |
| 156 #ifdef SK_DEBUG | 150 #ifdef SK_DEBUG |
| 157 // bounds sanity check | 151 // bounds sanity check |
| 158 SkRect rect; | 152 SkRect rect; |
| 159 rect.setLargestInverted(); | 153 rect.setLargestInverted(); |
| 160 SkPoint* vertex = (SkPoint*) ((char*)blobVertices); | 154 SkPoint* vertex = (SkPoint*) ((char*)blobVertices); |
| 161 rect.growToInclude(vertex, vertexStride, kVerticesPerGlyph * subRunGlyph
Count); | 155 rect.growToInclude(vertex, vertexStride, kVerticesPerGlyph * subRunGlyph
Count); |
| 162 | 156 |
| 163 if (this->usesDistanceFields()) { | 157 if (this->usesDistanceFields()) { |
| 164 args.fViewMatrix.mapRect(&rect); | 158 args.fViewMatrix.mapRect(&rect); |
| 165 } | 159 } |
| 166 // Allow for small numerical error in the bounds. | 160 // Allow for small numerical error in the bounds. |
| 167 SkRect bounds = fBounds; | 161 SkRect bounds = fBounds; |
| 168 bounds.outset(0.001f, 0.001f); | 162 bounds.outset(0.001f, 0.001f); |
| 169 SkASSERT(bounds.contains(rect)); | 163 SkASSERT(bounds.contains(rect)); |
| 170 #endif | 164 #endif |
| 171 | 165 |
| 172 currVertex += byteCount; | 166 currVertex += byteCount; |
| 173 } | 167 } |
| 174 | 168 |
| 175 // Make sure to attach the last cache if applicable | |
| 176 if (cache) { | |
| 177 SkGlyphCache::AttachCache(cache); | |
| 178 } | |
| 179 this->flush(target, &flushInfo); | 169 this->flush(target, &flushInfo); |
| 180 } | 170 } |
| 181 | 171 |
| 182 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo
) const { | 172 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo
) const { |
| 183 GrMesh mesh; | 173 GrMesh mesh; |
| 184 int maxGlyphsPerDraw = | 174 int maxGlyphsPerDraw = |
| 185 static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint1
6_t) / 6); | 175 static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint1
6_t) / 6); |
| 186 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, | 176 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, |
| 187 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, | 177 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, |
| 188 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyphsTo
Flush, | 178 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyphsTo
Flush, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 flags, | 303 flags, |
| 314 this->usesLocalCoords()); | 304 this->usesLocalCoords()); |
| 315 #endif | 305 #endif |
| 316 } | 306 } |
| 317 | 307 |
| 318 } | 308 } |
| 319 | 309 |
| 320 void GrBlobRegenHelper::flush() { | 310 void GrBlobRegenHelper::flush() { |
| 321 fBatch->flush(fTarget, fFlushInfo); | 311 fBatch->flush(fTarget, fFlushInfo); |
| 322 } | 312 } |
| OLD | NEW |