void onPrepareDraws(Target* target) const override { sk_sp<GrGeometryProcessor> gp = make_gp(fOverrides.readsCoverage(), fViewMatrix); if (!gp) { SkDebugf("Couldn't create GrGeometryProcessor\n"); return; } SkASSERT(gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionColorAttr)); int numRegions = fRegions.count(); int numRects = 0; for (int i = 0; i < numRegions; i++) { numRects += fRegions[i].fRegion.computeRegionComplexity(); } size_t vertexStride = gp->getVertexStride(); SkAutoTUnref<const GrBuffer> indexBuffer(target->resourceProvider()->refQuadIndexBuffer()); InstancedHelper helper; void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride, indexBuffer, kVertsPerInstance, kIndicesPerInstance, numRects); if (!vertices || !indexBuffer) { SkDebugf("Could not allocate vertices\n"); return; } intptr_t verts = reinterpret_cast<intptr_t>(vertices); for (int i = 0; i < numRegions; i++) { tesselate_region(verts, vertexStride, fRegions[i].fColor, fRegions[i].fRegion); int numRectsInRegion = fRegions[i].fRegion.computeRegionComplexity(); verts += numRectsInRegion * kVertsPerInstance * vertexStride; } helper.recordDraw(target, gp.get()); }
void onPrepareDraws(Target* target) override { SkAutoTUnref<const GrGeometryProcessor> gp(create_gp(fOverrides.readsCoverage())); if (!gp) { SkDebugf("Couldn't create GrGeometryProcessor\n"); return; } target->initDraw(gp, this->pipeline()); size_t vertexStride = gp->getVertexStride(); int instanceCount = fGeoData.count(); SkAutoTUnref<const GrIndexBuffer> indexBuffer( target->resourceProvider()->refQuadIndexBuffer()); InstancedHelper helper; void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride, indexBuffer, kVertsPerRect, kIndicesPerRect, instanceCount * kRectsPerInstance); if (!vertices || !indexBuffer) { SkDebugf("Could not allocate vertices\n"); return; } for (int i = 0; i < instanceCount; i++) { intptr_t verts = reinterpret_cast<intptr_t>(vertices) + i * kRectsPerInstance * kVertsPerRect * vertexStride; Geometry& geo = fGeoData[i]; SkNinePatchIter iter(fImageWidth, fImageHeight, geo.fCenter, geo.fDst); SkRect srcR, dstR; while (iter.next(&srcR, &dstR)) { SkPoint* positions = reinterpret_cast<SkPoint*>(verts); positions->setRectFan(dstR.fLeft, dstR.fTop, dstR.fRight, dstR.fBottom, vertexStride); SkASSERT(!geo.fViewMatrix.hasPerspective()); geo.fViewMatrix.mapPointsWithStride(positions, vertexStride, kVertsPerRect); // Setup local coords static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); SkPoint* coords = reinterpret_cast<SkPoint*>(verts + kLocalOffset); coords->setRectFan(srcR.fLeft, srcR.fTop, srcR.fRight, srcR.fBottom, vertexStride); static const int kColorOffset = sizeof(SkPoint); GrColor* vertColor = reinterpret_cast<GrColor*>(verts + kColorOffset); for (int j = 0; j < 4; ++j) { *vertColor = geo.fColor; vertColor = (GrColor*) ((intptr_t) vertColor + vertexStride); } verts += kVertsPerRect * vertexStride; } } helper.recordDraw(target); }
void AAStrokeRectBatch::onPrepareDraws(Target* target) const { bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); SkAutoTUnref<const GrGeometryProcessor> gp(create_stroke_rect_gp(canTweakAlphaForCoverage, this->viewMatrix(), this->usesLocalCoords(), this->coverageIgnored())); if (!gp) { SkDebugf("Couldn't create GrGeometryProcessor\n"); return; } target->initDraw(gp); size_t vertexStride = gp->getVertexStride(); SkASSERT(canTweakAlphaForCoverage ? vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) : vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); int innerVertexNum = 4; int outerVertexNum = this->miterStroke() ? 4 : 8; int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIndexCnt; int instanceCount = fGeoData.count(); const SkAutoTUnref<const GrBuffer> indexBuffer( GetIndexBuffer(target->resourceProvider(), this->miterStroke())); InstancedHelper helper; void* vertices = helper.init(target, kTriangles_GrPrimitiveType, vertexStride, indexBuffer, verticesPerInstance, indicesPerInstance, instanceCount); if (!vertices || !indexBuffer) { SkDebugf("Could not allocate vertices\n"); return; } for (int i = 0; i < instanceCount; i++) { const Geometry& args = fGeoData[i]; this->generateAAStrokeRectGeometry(vertices, i * verticesPerInstance * vertexStride, vertexStride, outerVertexNum, innerVertexNum, args.fColor, args.fDevOutside, args.fDevOutsideAssist, args.fDevInside, fMiterStroke, args.fDegenerate, canTweakAlphaForCoverage); } helper.recordDraw(target); }