Chromium Code Reviews| 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" | |
| 23 #include "GrStrokeInfo.h" | 22 #include "GrStrokeInfo.h" |
| 24 #include "GrVertexBuffer.h" | 23 #include "GrVertexBuffer.h" |
| 25 #include "SkGr.h" | 24 #include "SkGr.h" |
| 26 #include "gl/GrGLGeometryProcessor.h" | 25 #include "gl/GrGLGeometryProcessor.h" |
| 27 #include "gl/GrGLProcessor.h" | 26 #include "gl/GrGLProcessor.h" |
| 28 #include "gl/GrGLSL.h" | 27 #include "gl/GrGLSL.h" |
| 29 #include "gl/builders/GrGLProgramBuilder.h" | 28 #include "gl/builders/GrGLProgramBuilder.h" |
| 30 | 29 |
| 31 /////////////////////////////////////////////////////////////////////////////// | 30 /////////////////////////////////////////////////////////////////////////////// |
| 32 | 31 |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 draw.fStartOffset = startOffset; | 528 draw.fStartOffset = startOffset; |
| 530 draw.fDevBloatX = devBloatX; | 529 draw.fDevBloatX = devBloatX; |
| 531 draw.fDevBloatY = devBloatY; | 530 draw.fDevBloatY = devBloatY; |
| 532 draw.fHalfDevStroke = halfDevStroke; | 531 draw.fHalfDevStroke = halfDevStroke; |
| 533 draw.fStrokeWidth = strokeWidth; | 532 draw.fStrokeWidth = strokeWidth; |
| 534 draw.fHasStartRect = hasStartRect; | 533 draw.fHasStartRect = hasStartRect; |
| 535 draw.fLineDone = lineDone; | 534 draw.fLineDone = lineDone; |
| 536 draw.fHasEndRect = hasEndRect; | 535 draw.fHasEndRect = hasEndRect; |
| 537 } | 536 } |
| 538 | 537 |
| 539 SkAutoTUnref<const GrIndexBuffer> indexBuffer( | 538 QuadHelper helper; |
| 540 batchTarget->resourceProvider()->refQuadIndexBuffer()); | 539 void* vertices = helper.init(batchTarget, gp->getVertexStride(), instanc eCount); |
| 541 | 540 if (!vertices) { |
| 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"); | |
| 551 return; | 541 return; |
| 552 } | 542 } |
| 553 | 543 |
| 554 int curVIdx = 0; | 544 int curVIdx = 0; |
| 555 int rectIndex = 0; | 545 int rectIndex = 0; |
| 556 for (int i = 0; i < instanceCount; i++) { | 546 for (int i = 0; i < instanceCount; i++) { |
| 557 Geometry& args = fGeoData[i]; | 547 Geometry& geom = fGeoData[i]; |
| 558 | 548 |
| 559 if (!draws[i].fLineDone) { | 549 if (!draws[i].fLineDone) { |
| 560 if (fullDash) { | 550 if (fullDash) { |
| 561 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, args. fSrcRotInv, | 551 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom. fSrcRotInv, |
| 562 draws[i].fStartOffset, draws[i].fDevBloatX , | 552 draws[i].fStartOffset, draws[i].fDevBloatX , |
| 563 draws[i].fDevBloatY, draws[i].fLineLength, | 553 draws[i].fDevBloatY, draws[i].fLineLength, |
| 564 draws[i].fHalfDevStroke, args.fIntervals[0 ], | 554 draws[i].fHalfDevStroke, geom.fIntervals[0 ], |
| 565 args.fIntervals[1], draws[i].fStrokeWidth, | 555 geom.fIntervals[1], draws[i].fStrokeWidth, |
| 566 capType, gp->getVertexStride()); | 556 capType, gp->getVertexStride()); |
| 567 } else { | 557 } else { |
| 568 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); | 558 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); |
| 569 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 559 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 570 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo tInv, verts); | 560 setup_dashed_rect_pos(rects[rectIndex], curVIdx, geom.fSrcRo tInv, verts); |
| 571 } | 561 } |
| 572 curVIdx += 4; | 562 curVIdx += 4; |
| 573 } | 563 } |
| 574 rectIndex++; | 564 rectIndex++; |
| 575 | 565 |
| 576 if (draws[i].fHasStartRect) { | 566 if (draws[i].fHasStartRect) { |
| 577 if (fullDash) { | 567 if (fullDash) { |
| 578 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, args. fSrcRotInv, | 568 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom. fSrcRotInv, |
| 579 draws[i].fStartOffset, draws[i].fDevBloatX , | 569 draws[i].fStartOffset, draws[i].fDevBloatX , |
| 580 draws[i].fDevBloatY, args.fIntervals[0], | 570 draws[i].fDevBloatY, geom.fIntervals[0], |
| 581 draws[i].fHalfDevStroke, args.fIntervals[0 ], | 571 draws[i].fHalfDevStroke, geom.fIntervals[0 ], |
| 582 args.fIntervals[1], draws[i].fStrokeWidth, capType, | 572 geom.fIntervals[1], draws[i].fStrokeWidth, capType, |
| 583 gp->getVertexStride()); | 573 gp->getVertexStride()); |
| 584 } else { | 574 } else { |
| 585 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); | 575 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); |
| 586 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 576 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 587 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo tInv, verts); | 577 setup_dashed_rect_pos(rects[rectIndex], curVIdx, geom.fSrcRo tInv, verts); |
| 588 } | 578 } |
| 589 | 579 |
| 590 curVIdx += 4; | 580 curVIdx += 4; |
| 591 } | 581 } |
| 592 rectIndex++; | 582 rectIndex++; |
| 593 | 583 |
| 594 if (draws[i].fHasEndRect) { | 584 if (draws[i].fHasEndRect) { |
| 595 if (fullDash) { | 585 if (fullDash) { |
| 596 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, args. fSrcRotInv, | 586 setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom. fSrcRotInv, |
| 597 draws[i].fStartOffset, draws[i].fDevBloatX , | 587 draws[i].fStartOffset, draws[i].fDevBloatX , |
| 598 draws[i].fDevBloatY, args.fIntervals[0], | 588 draws[i].fDevBloatY, geom.fIntervals[0], |
| 599 draws[i].fHalfDevStroke, args.fIntervals[0 ], | 589 draws[i].fHalfDevStroke, geom.fIntervals[0 ], |
| 600 args.fIntervals[1], draws[i].fStrokeWidth, capType, | 590 geom.fIntervals[1], draws[i].fStrokeWidth, capType, |
| 601 gp->getVertexStride()); | 591 gp->getVertexStride()); |
| 602 } else { | 592 } else { |
| 603 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); | 593 SkPoint* verts = reinterpret_cast<SkPoint*>(vertices); |
| 604 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); | 594 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); |
| 605 setup_dashed_rect_pos(rects[rectIndex], curVIdx, args.fSrcRo tInv, verts); | 595 setup_dashed_rect_pos(rects[rectIndex], curVIdx, geom.fSrcRo tInv, verts); |
| 606 } | 596 } |
| 607 curVIdx += 4; | 597 curVIdx += 4; |
| 598 rectIndex++; | |
|
joshualitt
2015/05/04 13:48:28
is this move intentional?
bsalomon
2015/05/04 15:43:27
No, undone.
| |
| 608 } | 599 } |
| 609 rectIndex++; | |
| 610 } | 600 } |
| 611 | 601 helper.issueDraws(batchTarget); |
| 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 } | |
| 633 } | 602 } |
| 634 | 603 |
| 635 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 604 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 636 | 605 |
| 637 private: | 606 private: |
| 638 DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, boo l fullDash) { | 607 DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, boo l fullDash) { |
| 639 this->initClassID<DashBatch>(); | 608 this->initClassID<DashBatch>(); |
| 640 fGeoData.push_back(geometry); | 609 fGeoData.push_back(geometry); |
| 641 | 610 |
| 642 fBatch.fAAMode = aaMode; | 611 fBatch.fAAMode = aaMode; |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1372 info.fIntervals = intervals; | 1341 info.fIntervals = intervals; |
| 1373 info.fCount = 2; | 1342 info.fCount = 2; |
| 1374 info.fPhase = phase; | 1343 info.fPhase = phase; |
| 1375 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1344 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
| 1376 SkASSERT(success); | 1345 SkASSERT(success); |
| 1377 | 1346 |
| 1378 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1347 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
| 1379 } | 1348 } |
| 1380 | 1349 |
| 1381 #endif | 1350 #endif |
| OLD | NEW |