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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 90 } |
91 | 91 |
92 GrTexture* texture = fFontCache->getTexture(this->maskFormat()); | 92 GrTexture* texture = fFontCache->getTexture(this->maskFormat()); |
93 if (!texture) { | 93 if (!texture) { |
94 SkDebugf("Could not allocate backing texture for atlas\n"); | 94 SkDebugf("Could not allocate backing texture for atlas\n"); |
95 return; | 95 return; |
96 } | 96 } |
97 | 97 |
98 GrMaskFormat maskFormat = this->maskFormat(); | 98 GrMaskFormat maskFormat = this->maskFormat(); |
99 | 99 |
100 SkAutoTUnref<const GrGeometryProcessor> gp; | 100 FlushInfo flushInfo; |
101 if (this->usesDistanceFields()) { | 101 if (this->usesDistanceFields()) { |
102 gp.reset(this->setupDfProcessor(this->viewMatrix(), fFilteredColor, this
->color(), | 102 flushInfo.fGeometryProcessor.reset( |
103 texture)); | 103 this->setupDfProcessor(this->viewMatrix(), fFilteredColor, this->col
or(), texture)); |
104 } else { | 104 } else { |
105 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone
_FilterMode); | 105 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kNone
_FilterMode); |
106 gp.reset(GrBitmapTextGeoProc::Create(this->color(), | 106 flushInfo.fGeometryProcessor.reset( |
107 texture, | 107 GrBitmapTextGeoProc::Create(this->color(), |
108 params, | 108 texture, |
109 maskFormat, | 109 params, |
110 localMatrix, | 110 maskFormat, |
111 this->usesLocalCoords())); | 111 localMatrix, |
| 112 this->usesLocalCoords())); |
112 } | 113 } |
113 | 114 |
114 FlushInfo flushInfo; | |
115 flushInfo.fGlyphsToFlush = 0; | 115 flushInfo.fGlyphsToFlush = 0; |
116 size_t vertexStride = gp->getVertexStride(); | 116 size_t vertexStride = flushInfo.fGeometryProcessor->getVertexStride(); |
117 SkASSERT(vertexStride == GrAtlasTextBlob::GetVertexStride(maskFormat)); | 117 SkASSERT(vertexStride == GrAtlasTextBlob::GetVertexStride(maskFormat)); |
118 | 118 |
119 target->initDraw(gp); | |
120 | |
121 int glyphCount = this->numGlyphs(); | 119 int glyphCount = this->numGlyphs(); |
122 const GrBuffer* vertexBuffer; | 120 const GrBuffer* vertexBuffer; |
123 | 121 |
124 void* vertices = target->makeVertexSpace(vertexStride, | 122 void* vertices = target->makeVertexSpace(vertexStride, |
125 glyphCount * kVerticesPerGlyph, | 123 glyphCount * kVerticesPerGlyph, |
126 &vertexBuffer, | 124 &vertexBuffer, |
127 &flushInfo.fVertexOffset); | 125 &flushInfo.fVertexOffset); |
128 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); | 126 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); |
129 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuffer(
)); | 127 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuffer(
)); |
130 if (!vertices || !flushInfo.fVertexBuffer) { | 128 if (!vertices || !flushInfo.fVertexBuffer) { |
131 SkDebugf("Could not allocate vertices\n"); | 129 SkDebugf("Could not allocate vertices\n"); |
132 return; | 130 return; |
133 } | 131 } |
134 | 132 |
135 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); | 133 unsigned char* currVertex = reinterpret_cast<unsigned char*>(vertices); |
136 | 134 |
137 // We cache some values to avoid going to the glyphcache for the same fontSc
aler twice | 135 // We cache some values to avoid going to the glyphcache for the same fontSc
aler twice |
138 // in a row | 136 // in a row |
139 const SkDescriptor* desc = nullptr; | 137 const SkDescriptor* desc = nullptr; |
140 SkGlyphCache* cache = nullptr; | 138 SkGlyphCache* cache = nullptr; |
141 GrFontScaler* scaler = nullptr; | 139 GrFontScaler* scaler = nullptr; |
142 SkTypeface* typeface = nullptr; | 140 SkTypeface* typeface = nullptr; |
143 | 141 |
144 GrBlobRegenHelper helper(this, target, &flushInfo, gp); | 142 GrBlobRegenHelper helper(this, target, &flushInfo); |
145 | 143 |
146 for (int i = 0; i < fGeoCount; i++) { | 144 for (int i = 0; i < fGeoCount; i++) { |
147 const Geometry& args = fGeoData[i]; | 145 const Geometry& args = fGeoData[i]; |
148 Blob* blob = args.fBlob; | 146 Blob* blob = args.fBlob; |
149 size_t byteCount; | 147 size_t byteCount; |
150 void* blobVertices; | 148 void* blobVertices; |
151 int subRunGlyphCount; | 149 int subRunGlyphCount; |
152 blob->regenInBatch(target, fFontCache, &helper, args.fRun, args.fSubRun,
&cache, | 150 blob->regenInBatch(target, fFontCache, &helper, args.fRun, args.fSubRun,
&cache, |
153 &typeface, &scaler, &desc, vertexStride, args.fViewMa
trix, args.fX, | 151 &typeface, &scaler, &desc, vertexStride, args.fViewMa
trix, args.fX, |
154 args.fY, args.fColor, &blobVertices, &byteCount, &sub
RunGlyphCount); | 152 args.fY, args.fColor, &blobVertices, &byteCount, &sub
RunGlyphCount); |
(...skipping 25 matching lines...) Expand all Loading... |
180 } | 178 } |
181 | 179 |
182 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo
) const { | 180 void GrAtlasTextBatch::flush(GrVertexBatch::Target* target, FlushInfo* flushInfo
) const { |
183 GrMesh mesh; | 181 GrMesh mesh; |
184 int maxGlyphsPerDraw = | 182 int maxGlyphsPerDraw = |
185 static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint1
6_t) / 6); | 183 static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint1
6_t) / 6); |
186 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, | 184 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, |
187 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, | 185 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, |
188 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyphsTo
Flush, | 186 kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyphsTo
Flush, |
189 maxGlyphsPerDraw); | 187 maxGlyphsPerDraw); |
190 target->draw(mesh); | 188 target->draw(flushInfo->fGeometryProcessor, mesh); |
191 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; | 189 flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush; |
192 flushInfo->fGlyphsToFlush = 0; | 190 flushInfo->fGlyphsToFlush = 0; |
193 } | 191 } |
194 | 192 |
195 bool GrAtlasTextBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { | 193 bool GrAtlasTextBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { |
196 GrAtlasTextBatch* that = t->cast<GrAtlasTextBatch>(); | 194 GrAtlasTextBatch* that = t->cast<GrAtlasTextBatch>(); |
197 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeli
ne(), | 195 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeli
ne(), |
198 that->bounds(), caps)) { | 196 that->bounds(), caps)) { |
199 return false; | 197 return false; |
200 } | 198 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 params, | 305 params, |
308 flags, | 306 flags, |
309 this->usesLocalCoords()); | 307 this->usesLocalCoords()); |
310 #endif | 308 #endif |
311 } | 309 } |
312 | 310 |
313 } | 311 } |
314 | 312 |
315 void GrBlobRegenHelper::flush() { | 313 void GrBlobRegenHelper::flush() { |
316 fBatch->flush(fTarget, fFlushInfo); | 314 fBatch->flush(fTarget, fFlushInfo); |
317 fTarget->initDraw(fGP); | |
318 } | 315 } |
OLD | NEW |