| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrDashingEffect.h" | 8 #include "GrDashingEffect.h" |
| 9 | 9 |
| 10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
| 11 #include "GrBatchTarget.h" | 11 #include "GrBatchTarget.h" |
| 12 #include "GrBatchTest.h" | 12 #include "GrBatchTest.h" |
| 13 #include "GrBufferAllocPool.h" | 13 #include "GrBufferAllocPool.h" |
| 14 #include "GrGeometryProcessor.h" | 14 #include "GrGeometryProcessor.h" |
| 15 #include "GrContext.h" | 15 #include "GrContext.h" |
| 16 #include "GrCoordTransform.h" | 16 #include "GrCoordTransform.h" |
| 17 #include "GrDefaultGeoProcFactory.h" | 17 #include "GrDefaultGeoProcFactory.h" |
| 18 #include "GrDrawTarget.h" | 18 #include "GrDrawTarget.h" |
| 19 #include "GrDrawTargetCaps.h" | 19 #include "GrDrawTargetCaps.h" |
| 20 #include "GrInvariantOutput.h" | 20 #include "GrInvariantOutput.h" |
| 21 #include "GrProcessor.h" | 21 #include "GrProcessor.h" |
| 22 #include "GrResourceProvider.h" |
| 22 #include "GrStrokeInfo.h" | 23 #include "GrStrokeInfo.h" |
| 23 #include "GrVertexBuffer.h" | 24 #include "GrVertexBuffer.h" |
| 24 #include "SkGr.h" | 25 #include "SkGr.h" |
| 25 #include "gl/GrGLGeometryProcessor.h" | 26 #include "gl/GrGLGeometryProcessor.h" |
| 26 #include "gl/GrGLProcessor.h" | 27 #include "gl/GrGLProcessor.h" |
| 27 #include "gl/GrGLSL.h" | 28 #include "gl/GrGLSL.h" |
| 28 #include "gl/builders/GrGLProgramBuilder.h" | 29 #include "gl/builders/GrGLProgramBuilder.h" |
| 29 | 30 |
| 30 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
| 31 | 32 |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 draw.fStartOffset = startOffset; | 529 draw.fStartOffset = startOffset; |
| 529 draw.fDevBloatX = devBloatX; | 530 draw.fDevBloatX = devBloatX; |
| 530 draw.fDevBloatY = devBloatY; | 531 draw.fDevBloatY = devBloatY; |
| 531 draw.fHalfDevStroke = halfDevStroke; | 532 draw.fHalfDevStroke = halfDevStroke; |
| 532 draw.fStrokeWidth = strokeWidth; | 533 draw.fStrokeWidth = strokeWidth; |
| 533 draw.fHasStartRect = hasStartRect; | 534 draw.fHasStartRect = hasStartRect; |
| 534 draw.fLineDone = lineDone; | 535 draw.fLineDone = lineDone; |
| 535 draw.fHasEndRect = hasEndRect; | 536 draw.fHasEndRect = hasEndRect; |
| 536 } | 537 } |
| 537 | 538 |
| 538 QuadHelper helper; | 539 SkAutoTUnref<const GrIndexBuffer> indexBuffer( |
| 539 void* vertices = helper.init(batchTarget, gp->getVertexStride(), instanc
eCount); | 540 batchTarget->resourceProvider()->refQuadIndexBuffer()); |
| 540 if (!vertices) { | 541 |
| 542 const GrVertexBuffer* vertexBuffer; |
| 543 int firstVertex; |
| 544 size_t vertexStride = gp->getVertexStride(); |
| 545 void* vertices = batchTarget->vertexPool()->makeSpace(vertexStride, |
| 546 totalRectCount * k
VertsPerDash, |
| 547 &vertexBuffer, |
| 548 &firstVertex); |
| 549 if (!vertices || !indexBuffer) { |
| 550 SkDebugf("Could not allocate buffers\n"); |
| 541 return; | 551 return; |
| 542 } | 552 } |
| 543 | 553 |
| 544 int curVIdx = 0; | 554 int curVIdx = 0; |
| 545 int rectIndex = 0; | 555 int rectIndex = 0; |
| 546 for (int i = 0; i < instanceCount; i++) { | 556 for (int i = 0; i < instanceCount; i++) { |
| 547 Geometry& geom = fGeoData[i]; | 557 Geometry& args = fGeoData[i]; |
| 548 | 558 |
| 549 if (!draws[i].fLineDone) { | 559 if (!draws[i].fLineDone) { |
| 550 if (fullDash) { | 560 if (fullDash) { |
| 551 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom.
fSrcRotInv, | 561 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, args.
fSrcRotInv, |
| 552 draws[i].fStartOffset, draws[i].fDevBloatX
, | 562 draws[i].fStartOffset, draws[i].fDevBloatX
, |
| 553 draws[i].fDevBloatY, draws[i].fLineLength, | 563 draws[i].fDevBloatY, draws[i].fLineLength, |
| 554 draws[i].fHalfDevStroke, geom.fIntervals[0
], | 564 draws[i].fHalfDevStroke, args.fIntervals[0
], |
| 555 geom.fIntervals[1], draws[i].fStrokeWidth, | 565 args.fIntervals[1], draws[i].fStrokeWidth, |
| 556 capType, gp->getVertexStride()); | 566 capType, gp->getVertexStride()); |
| 557 } else { | 567 } else { |
| 558 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); | 568 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); |
| 559 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 569 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 560 setup_dashed_rect_pos(rects[rectIndex], curVIdx, geom.fSrcRo
tInv, verts); | 570 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo
tInv, verts); |
| 561 } | 571 } |
| 562 curVIdx += 4; | 572 curVIdx += 4; |
| 563 } | 573 } |
| 564 rectIndex++; | 574 rectIndex++; |
| 565 | 575 |
| 566 if (draws[i].fHasStartRect) { | 576 if (draws[i].fHasStartRect) { |
| 567 if (fullDash) { | 577 if (fullDash) { |
| 568 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom.
fSrcRotInv, | 578 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, args.
fSrcRotInv, |
| 569 draws[i].fStartOffset, draws[i].fDevBloatX
, | 579 draws[i].fStartOffset, draws[i].fDevBloatX
, |
| 570 draws[i].fDevBloatY, geom.fIntervals[0], | 580 draws[i].fDevBloatY, args.fIntervals[0], |
| 571 draws[i].fHalfDevStroke, geom.fIntervals[0
], | 581 draws[i].fHalfDevStroke, args.fIntervals[0
], |
| 572 geom.fIntervals[1], draws[i].fStrokeWidth,
capType, | 582 args.fIntervals[1], draws[i].fStrokeWidth,
capType, |
| 573 gp->getVertexStride()); | 583 gp->getVertexStride()); |
| 574 } else { | 584 } else { |
| 575 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); | 585 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); |
| 576 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 586 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 577 setup_dashed_rect_pos(rects[rectIndex], curVIdx, geom.fSrcRo
tInv, verts); | 587 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo
tInv, verts); |
| 578 } | 588 } |
| 579 | 589 |
| 580 curVIdx += 4; | 590 curVIdx += 4; |
| 581 } | 591 } |
| 582 rectIndex++; | 592 rectIndex++; |
| 583 | 593 |
| 584 if (draws[i].fHasEndRect) { | 594 if (draws[i].fHasEndRect) { |
| 585 if (fullDash) { | 595 if (fullDash) { |
| 586 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom.
fSrcRotInv, | 596 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, args.
fSrcRotInv, |
| 587 draws[i].fStartOffset, draws[i].fDevBloatX
, | 597 draws[i].fStartOffset, draws[i].fDevBloatX
, |
| 588 draws[i].fDevBloatY, geom.fIntervals[0], | 598 draws[i].fDevBloatY, args.fIntervals[0], |
| 589 draws[i].fHalfDevStroke, geom.fIntervals[0
], | 599 draws[i].fHalfDevStroke, args.fIntervals[0
], |
| 590 geom.fIntervals[1], draws[i].fStrokeWidth,
capType, | 600 args.fIntervals[1], draws[i].fStrokeWidth,
capType, |
| 591 gp->getVertexStride()); | 601 gp->getVertexStride()); |
| 592 } else { | 602 } else { |
| 593 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); | 603 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); |
| 594 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 604 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 595 setup_dashed_rect_pos(rects[rectIndex], curVIdx, geom.fSrcRo
tInv, verts); | 605 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo
tInv, verts); |
| 596 } | 606 } |
| 597 curVIdx += 4; | 607 curVIdx += 4; |
| 598 } | 608 } |
| 599 rectIndex++; | 609 rectIndex++; |
| 600 } | 610 } |
| 601 helper.issueDraws(batchTarget); | 611 |
| 612 GrDrawTarget::DrawInfo drawInfo; |
| 613 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); |
| 614 drawInfo.setStartVertex(0); |
| 615 drawInfo.setStartIndex(0); |
| 616 drawInfo.setVerticesPerInstance(kVertsPerDash); |
| 617 drawInfo.setIndicesPerInstance(kIndicesPerDash); |
| 618 drawInfo.adjustStartVertex(firstVertex); |
| 619 drawInfo.setVertexBuffer(vertexBuffer); |
| 620 drawInfo.setIndexBuffer(indexBuffer); |
| 621 |
| 622 int maxInstancesPerDraw = indexBuffer->maxQuads(); |
| 623 while (totalRectCount) { |
| 624 drawInfo.setInstanceCount(SkTMin(totalRectCount, maxInstancesPerDraw
)); |
| 625 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); |
| 626 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); |
| 627 |
| 628 batchTarget->draw(drawInfo); |
| 629 |
| 630 drawInfo.setStartVertex(drawInfo.startVertex() + drawInfo.vertexCoun
t()); |
| 631 totalRectCount -= drawInfo.instanceCount(); |
| 632 } |
| 602 } | 633 } |
| 603 | 634 |
| 604 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 635 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 605 | 636 |
| 606 private: | 637 private: |
| 607 DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, boo
l fullDash) { | 638 DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, boo
l fullDash) { |
| 608 this->initClassID<DashBatch>(); | 639 this->initClassID<DashBatch>(); |
| 609 fGeoData.push_back(geometry); | 640 fGeoData.push_back(geometry); |
| 610 | 641 |
| 611 fBatch.fAAMode = aaMode; | 642 fBatch.fAAMode = aaMode; |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 info.fIntervals = intervals; | 1372 info.fIntervals = intervals; |
| 1342 info.fCount = 2; | 1373 info.fCount = 2; |
| 1343 info.fPhase = phase; | 1374 info.fPhase = phase; |
| 1344 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1375 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
| 1345 SkASSERT(success); | 1376 SkASSERT(success); |
| 1346 | 1377 |
| 1347 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1378 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
| 1348 } | 1379 } |
| 1349 | 1380 |
| 1350 #endif | 1381 #endif |
| OLD | NEW |