OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrAADistanceFieldPathRenderer.h" | 9 #include "GrAADistanceFieldPathRenderer.h" |
10 | 10 |
11 #include "GrBatch.h" | 11 #include "GrBatch.h" |
12 #include "GrBatchTarget.h" | 12 #include "GrBatchTarget.h" |
13 #include "GrBufferAllocPool.h" | 13 #include "GrBufferAllocPool.h" |
14 #include "GrContext.h" | 14 #include "GrContext.h" |
15 #include "GrPipelineBuilder.h" | 15 #include "GrPipelineBuilder.h" |
16 #include "GrSurfacePriv.h" | 16 #include "GrSurfacePriv.h" |
17 #include "GrSWMaskHelper.h" | 17 #include "GrSWMaskHelper.h" |
| 18 #include "GrResourceProvider.h" |
18 #include "GrTexturePriv.h" | 19 #include "GrTexturePriv.h" |
19 #include "GrVertexBuffer.h" | 20 #include "GrVertexBuffer.h" |
20 #include "effects/GrDistanceFieldGeoProc.h" | 21 #include "effects/GrDistanceFieldGeoProc.h" |
21 | 22 |
22 #include "SkDistanceFieldGen.h" | 23 #include "SkDistanceFieldGen.h" |
23 #include "SkRTConf.h" | 24 #include "SkRTConf.h" |
24 | 25 |
25 #define ATLAS_TEXTURE_WIDTH 1024 | 26 #define ATLAS_TEXTURE_WIDTH 1024 |
26 #define ATLAS_TEXTURE_HEIGHT 2048 | 27 #define ATLAS_TEXTURE_HEIGHT 2048 |
27 #define PLOT_WIDTH 256 | 28 #define PLOT_WIDTH 256 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 SkAutoTUnref<GrGeometryProcessor> dfProcessor( | 188 SkAutoTUnref<GrGeometryProcessor> dfProcessor( |
188 GrDistanceFieldPathGeoProc::Create(this->color(), | 189 GrDistanceFieldPathGeoProc::Create(this->color(), |
189 this->viewMatrix(), | 190 this->viewMatrix(), |
190 atlas->getTexture(), | 191 atlas->getTexture(), |
191 params, | 192 params, |
192 flags, | 193 flags, |
193 false)); | 194 false)); |
194 | 195 |
195 this->initDraw(batchTarget, dfProcessor, pipeline); | 196 this->initDraw(batchTarget, dfProcessor, pipeline); |
196 | 197 |
| 198 static const int kVertsPerQuad = 4; |
| 199 static const int kIndicesPerQuad = 6; |
| 200 |
| 201 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
| 202 batchTarget->resourceProvider()->refQuadIndexBuffer()); |
| 203 |
197 // allocate vertices | 204 // allocate vertices |
198 size_t vertexStride = dfProcessor->getVertexStride(); | 205 size_t vertexStride = dfProcessor->getVertexStride(); |
199 SkASSERT(vertexStride == 2 * sizeof(SkPoint)); | 206 SkASSERT(vertexStride == 2 * sizeof(SkPoint)); |
200 | |
201 int vertexCount = GrBatchTarget::kVertsPerRect * instanceCount; | |
202 | |
203 const GrVertexBuffer* vertexBuffer; | 207 const GrVertexBuffer* vertexBuffer; |
| 208 int vertexCount = kVertsPerQuad * instanceCount; |
204 int firstVertex; | 209 int firstVertex; |
205 | 210 |
206 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, | 211 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
207 vertexCount, | 212 vertexCount, |
208 &vertexBuffer, | 213 &vertexBuffer, |
209 &firstVertex); | 214 &firstVertex); |
210 | 215 |
211 if (!vertices) { | 216 if (!vertices || !indexBuffer) { |
212 SkDebugf("Could not allocate vertices\n"); | 217 SkDebugf("Could not allocate vertices\n"); |
213 return; | 218 return; |
214 } | 219 } |
215 | 220 |
216 // We may have to flush while uploading path data to the atlas, so we se
t up the draw here | 221 // We may have to flush while uploading path data to the atlas, so we se
t up the draw here |
217 const GrIndexBuffer* quadIndexBuffer = batchTarget->quadIndexBuffer(); | 222 int maxInstancesPerDraw = indexBuffer->maxQuads(); |
218 int maxInstancesPerDraw = quadIndexBuffer->maxQuads(); | |
219 | 223 |
220 GrDrawTarget::DrawInfo drawInfo; | 224 GrDrawTarget::DrawInfo drawInfo; |
221 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | 225 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); |
222 drawInfo.setStartVertex(0); | 226 drawInfo.setStartVertex(0); |
223 drawInfo.setStartIndex(0); | 227 drawInfo.setStartIndex(0); |
224 drawInfo.setVerticesPerInstance(GrBatchTarget::kVertsPerRect); | 228 drawInfo.setVerticesPerInstance(kVertsPerQuad); |
225 drawInfo.setIndicesPerInstance(GrBatchTarget::kIndicesPerRect); | 229 drawInfo.setIndicesPerInstance(kIndicesPerQuad); |
226 drawInfo.adjustStartVertex(firstVertex); | 230 drawInfo.adjustStartVertex(firstVertex); |
227 drawInfo.setVertexBuffer(vertexBuffer); | 231 drawInfo.setVertexBuffer(vertexBuffer); |
228 drawInfo.setIndexBuffer(quadIndexBuffer); | 232 drawInfo.setIndexBuffer(indexBuffer); |
229 | 233 |
230 int instancesToFlush = 0; | 234 int instancesToFlush = 0; |
231 for (int i = 0; i < instanceCount; i++) { | 235 for (int i = 0; i < instanceCount; i++) { |
232 Geometry& args = fGeoData[i]; | 236 Geometry& args = fGeoData[i]; |
233 | 237 |
234 // get mip level | 238 // get mip level |
235 SkScalar maxScale = this->viewMatrix().getMaxScale(); | 239 SkScalar maxScale = this->viewMatrix().getMaxScale(); |
236 const SkRect& bounds = args.fPath.getBounds(); | 240 const SkRect& bounds = args.fPath.getBounds(); |
237 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); | 241 SkScalar maxDim = SkMaxScalar(bounds.width(), bounds.height()); |
238 SkScalar size = maxScale * maxDim; | 242 SkScalar size = maxScale * maxDim; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 scale)) { | 277 scale)) { |
274 SkDebugf("Can't rasterize path\n"); | 278 SkDebugf("Can't rasterize path\n"); |
275 return; | 279 return; |
276 } | 280 } |
277 } | 281 } |
278 | 282 |
279 atlas->setLastUseToken(args.fPathData->fID, batchTarget->currentToke
n()); | 283 atlas->setLastUseToken(args.fPathData->fID, batchTarget->currentToke
n()); |
280 | 284 |
281 // Now set vertices | 285 // Now set vertices |
282 intptr_t offset = reinterpret_cast<intptr_t>(vertices); | 286 intptr_t offset = reinterpret_cast<intptr_t>(vertices); |
283 offset += i * GrBatchTarget::kVertsPerRect * vertexStride; | 287 offset += i * kVertsPerQuad * vertexStride; |
284 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); | 288 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); |
285 this->drawPath(batchTarget, | 289 this->drawPath(batchTarget, |
286 atlas, | 290 atlas, |
287 pipeline, | 291 pipeline, |
288 dfProcessor, | 292 dfProcessor, |
289 positions, | 293 positions, |
290 vertexStride, | 294 vertexStride, |
291 this->viewMatrix(), | 295 this->viewMatrix(), |
292 args.fPath, | 296 args.fPath, |
293 args.fPathData); | 297 args.fPathData); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 geometry.fPath = path; | 614 geometry.fPath = path; |
611 geometry.fAntiAlias = antiAlias; | 615 geometry.fAntiAlias = antiAlias; |
612 | 616 |
613 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color
, viewMatrix, | 617 SkAutoTUnref<GrBatch> batch(AADistanceFieldPathBatch::Create(geometry, color
, viewMatrix, |
614 fAtlas, &fPathC
ache, &fPathList)); | 618 fAtlas, &fPathC
ache, &fPathList)); |
615 target->drawBatch(pipelineBuilder, batch); | 619 target->drawBatch(pipelineBuilder, batch); |
616 | 620 |
617 return true; | 621 return true; |
618 } | 622 } |
619 | 623 |
OLD | NEW |