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